Getting/setting the cell value

API of DataTable allows you to retrieve existing values of cells or set new ones.

Getting the value

To get the record object, you should use method item():

Getting the record object

grid = webix.ui({ 
    view:"datatable",
    data:[ {id:"row1", title:"The Shawshank Redemption", year:"1994"} ],
    ...
});
...
 
//'record' variable will contain an object of the related DataTable record
var record = grid.getItem("row1");
 
//you can access data members directly
var title = record.title;

Setting the value

To change the current value of a cell, you should use the following technique:

Setting the cell value

record = grid.getItem(row_id);
record[column_name] = new_value;
 
grid.refresh();
//or
grid.updateItem(row_id, record);

Methods refresh() and update() lead to one and the same result and don't have any specificity.

Getting values of cells range

When you work with a block of cells you can use 2 'special' methods allowing you to get values of several cells and perform some action on them:

  • mapCells - gets the current values of the specified cells (called for each specified cell by turn).

Reversing text in the specified cells range

grid.mapCells(start_row,start_col,numRows,numCols,
function(value, row_id, column_id, row_ind, col_ind){
        return value.toString().split("").reverse().join("");
});

Related sample:  Mapping cells

  • mapSelection - gets the current values of the selected cells ( called for each selected cell by turn).

Reversing text in all selected cells

grid.mapSelection(function(value){
        return value.toString().split("").reverse().join("");
});

Related sample:  Mapping selection

For more on the mentioned and other related methods, see API Reference.

Back to top