Work with Selection object
The selection object API lets you manage DataView items: select an item, remove selection, and get the id or the object of a selected DataView item.
Enabling/Disabling Selection object
From v7.0, you can enable item selection with the enable() method of the selection object:
dataview.selection.enable();
To disable item selection in DataView, use the disable() method of the selection object:
dataview.selection.disable();
Related sample: Dataview. Disable / enable selection
For finer control over item selection, apply the Selection object events.
Selecting an item
To select a DataView item, use the add() method of the selection object. The method takes an item id as a parameter:
const id = dataview.selection.getId(); // -> "2"
dataview.selection.add("2");
From v7.0, the method selects all unselected items when you call it 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 can take an item id as a parameter:
dataview.selection.remove("2");
From v7.0, the method unselects all previously selected items when you call it 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:
const selected = dataview.selection.getId(); // -> "2"
From v7.0, the method can also return an array of ids of selected items if the DataView multiselection property is enabled.
Getting object of a selected item
You can also get the object of a selected item with the getItem() method of the selection object:
const item = dataview.selection.getItem();
From v7.0, the method can also return an array of selected items if the DataView multiselection property is enabled.