The API of DataTable allows you to retrieve existing values of cells or set new ones.
To get the record object, you should use the getItem() method:
Getting the record object
grid = webix.ui({
view:"datatable",
data:[ {id:"row1", title:"The Shawshank Redemption", year:"1994"} ],
...
});
...
// the 'record' variable will contain an object of the related DataTable record
var record = grid.getItem("row1");
//you can access data fields directly
var title = record.title;
To change the current value of a cell, you should use the following technique:
Setting the cell value
grid.updateItem(row_id, { column_name: new_value });
//or
record = grid.getItem(row_id);
record[column_name] = new_value;
grid.refresh(row_id); // the item ID is optional
Methods refresh() and updateItem() will both update the related record, while the updateItem() will also trigger saving of this record to server side, if you have added a script for saving data.
When you work with a block of cells, you can use the methods that allow you to get values of several cells and perform some actions on them:
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("");
});
Reversing text in all selected cells
grid.mapSelection(function(value, row_id, column_id, row_ind, col_ind){
return value.toString().split("").reverse().join("");
});
Related sample: Mapping Selection
Read more in the API Reference.
Back to top