Skip to main content

Work with Selection object

You can manipulate with List 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 List item.

Enabling/Disabling Selection object

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

list.selection.enable();

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

list.selection.disable();

Related sample: List. Disable / enable selection

note

To make the process of working with the selection of items more flexible, you can apply the related events of the Selection object.

Selecting an item

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

const id = list.selection.getId(); // -> "2"
list.selection.add("2");

Related sample: List. Set selection

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

list.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:

list.selection.remove("2"); 

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

list.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 = list.selection.getId(); // -> "2"

Related sample: List. Get selection

Starting from v7.0, the method can also return an array with ids of selected items if the multiselection property of List 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:

const item = list.selection.getItem();

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