Getting the Value
The API of DataGrid allows you to retrieve existing values of cells or set new ones.
Getting the Value
Section titled “Getting the Value”To get the record object, you should use the getItem() method:
Getting the record object
var grid = webix.grid({ data:[ {id:"row1", title:"The Shawshank Redemption", year:"1994"} ], ...});...
// the 'record' variable will contain an object of the related DataGrid recordvar record = grid.getItem("row1");
//you can access data fields directlyvar title = record.title;
Setting the Value
Section titled “Setting the Value”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 });
//orrecord = 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.
Getting Values of Cells Range
Section titled “Getting Values of Cells Range”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:
- mapCells - gets the current values of the specified cells (called for each specified cell one by one).
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(""); });
- mapSelection - gets the current values of the selected cells (called for each selected cell one by one).
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.