Skip to main content

Work with Selection Object

You can manipulate with Grid cells via the API of the selection object. It is possible to get the object of a selected Grid cell or set the selection to a cell. The selection object also allows removing selection from previously selected cells.

Enabling/Disabling Selection object#

Starting from v7.0, you can activate selection of cells via the enable() method of the selection object.

treegrid.selection.enable();

To disable the Selection object, make use of the disable() method of the selection object:

treegrid.selection.disable();

Setting selection to a cell#

To set selection to a particular cell, make use of the setCell() method of the selection object. The method takes the following parameters:

row(object) an object with a cell to be selected
column(object) the config of a column

var row = treegrid.data.getItem(treegrid.data.getId(0));var column = treegrid.getColumn("population");treegrid.selection.setCell(row, column);

To make the process of selecting a cell more flexible, you can apply the related events of the selection object:

Removing selection#

Starting from v7.0, you can remove selection from a selected cell/row or from highlighted cells/rows using the removeCell() method of the selection object. The method takes two parameters:

rowId(string|number) optional, the id of a row
colId(string|number) optional, the id of a column

// unselects all previously selected cellstreegrid.selection.removeCell(); // unselects all previously selected cells of the specified rowtreegrid.selection.removeCell(rowId); // removes selection from the specified celltreegrid.selection.removeCell(rowId, colId);

To make the process of unselecting cells more flexible, you can apply the related events of the selection object:

Getting object of a selected cell#

To get the object of a selected TreeGrid cell, use the getCell() method of the selection object:

var selectedCell = treegrid.selection.getCell();// -> {row: {…}, column: {…}}