Getting/Setting Cell Value

The 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 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;

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 });
 
//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.

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("");
    });

Related sample:  Mapping Cells

  • 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.

Back to top
If you have not checked yet, be sure to visit site of our main product Webix js frameworks and page of javascript datatable product.