DHTMLX Docs & Samples Explorer

Index
dhtmlxDataView

## Selection

By default component initialize in multiselect mode. It can be controlled by using parameter of constructor , or by js API

         var view = new dhtmlXDataView({
              container:"some_html",
              select:"multiselect"
         });
         ...
         view.define("select",true);

Possible values

- false - disable selection
- true - enable selection ( single selection )
- “multiselect” - enable multi-selection

Single item can be selected by clicking on it.

Multiple items can be selected by using ctrl and shift keys while clicking on items.

To select item by API the next commands can be used

        view.select(id);
        view.unselect(id);
        view.selectAll();
        view.unselectAll();
        var bool = view.isSelected(id);
        var id = view.getSelected();

Calling select or unselect without parameter is equal to calling selectAll or unselectAll respectfully.

getSelected method returns an ID for single selection mode. In multiselection mode, if more than one element selected method will return an array.

During selection of items ( by user or by API ) the next events generated

- onBeforeSelect
- onAfterSelect
- onSelectChange

In case of single selection - all 3 events generated , if multiselection is enabled and ctrl-click or shift click occurs - only onSelectChange event will be generated.

In multiselect mode select command can use additional parameters

    //select in addition to existing ones
        view.select(id,true); //same as ctrl-click
    //select all items from previously selecte till current one
        view.select(id,false,true); //same as shift-click

Beware that select method only change selection and doesn't force item visibility, you will need to use show method to ensure that item is visible ( scrolled in visible part of dataview )

        view.show(id);