Work with Selection Object

You can manipulate with DataView items via the API of the selection object. It is possible to select an item, remove selection, and get the id or even the object of a selected DataView item.

Enabling/Disabling Selection object

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

dataview.selection.enable();

To disable selection of items in DataView, make use of the disable() method of the selection object:

dataview.selection.disable();

Related sample:  Disable/Enable selection - DHTMLX Dataview

Here is a list of events that you can apply while working with selection of items:

Selecting an item

To select a particular DataView item, make use of the add() method of the selection object. As a parameter the method takes the id of an item.

var id = dataview.selection.getId(); // -> "2"
dataview.selection.add("2");

Starting from v7.0, the method selects all unselected items when calling without parameters:

dataview.selection.add();

Unselecting an item

To remove selection from a selected item, apply the remove() method of the selection object. The method may take the id of an item as a parameter:

dataview.selection.remove("2");

Starting from v7.0, the method unselects all previously selected items when calling without parameters:

dataview.selection.remove();

Getting id of a selected item

You can get the id of the currently selected item with the getId() method of the selection object:

var selected = dataview.selection.getId(); // -> "2"

Starting from v7.0, the method can also return an array with ids of selected items if the multiselection property of DataView is enabled.

Getting object of a selected item

It is also possible to get the object of a selected item using the getItem() method of the selection object:

var item = dataview.selection.getItem();

Starting from v7.0, the method can also return an array of selected items if the multiselection property of DataView is enabled.

Back to top