Work with List

Setting focus on item

To set focus on a List item, make use of the setFocusIndex method. It takes the index of an item as a parameter:

list.setFocusIndex(7);

To get the index of a List item in focus, use the getFocusIndex method. It will return the index of an item in focus:

var index = list.getFocusIndex(); // -> 6

It is also possible to get the id of an item in focus. For this you need to call the getFocus method:

var focus = list.getFocus(); // -> "u1556534543152"

Using Data Collection API

You can manipulate List items with the help of the Data collection API.

Adding items into List

It is possible to add more items into the initialized List on the fly. Use the add() method of Data Collection. It takes two parameters:

  • config - (object) the configuration object of the added item
  • index - (number) optional, the position to add an item at
list.data.add({value:"New item"},1);

Updating List items

You can change config options of the item via the update() method of Data Collection. It takes two parameters:

  • id - the id of the item
  • config - an object with new configuration of the item

For example, you can change the value of an item:

list.data.update("option_id",{
    value:"Nice item"
});

Removing items from List

To remove an item, make use of the remove() method of Data Collection. Pass the id of the item that should be removed to the method:

list.data.remove("option_id");

Filtering List data

You can filter List data by the specified criteria with the help of the filter method of Data collection. Check all details on parameters of the method in the Data collection API.

list.data.filter({
    by:"value",
    match:2,
    compare:(value,match,item)=>{ return parseFloat(value) % 2 == 0}
});

Filtering can be applied to any attribute of a data item.

Sorting List data

It is possible to sort data in List via the sort method of Data collection. Check all details on parameters of the method in the Data collection API.

list.data.sort({ 
    by:"value",
    dir:"desc"
});

Sorting can be applied to any attribute of a data item.

Using Selection API

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.

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.

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

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

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

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 = list.selection.getItem();
Back to top