User Interaction
In the List UI component, selection is disabled by default. To enable it, choose one of selection modes using the selectionMode property.
- $(function() {
- $("#listContainer").dxList({
- // ...
- selectionMode: "single" // or "multiple" | "all" | "none" (disables selection)
- });
- });
To select a List item, an end user simply clicks or taps it. Selected items become shaded. If you want to indicate selected items more manifestly, set the showSelectionControls property to true. This setting adds a check box to each item on the List. Also, make this setting if you use the "all" selectionMode. Otherwise, the "Select All" check box will be missing.
- $(function() {
- $("#listContainer").dxList({
- // ...
- showSelectionControls: true
- });
- });
When data in the List is paginated, you can choose whether the "Select All" check box will select all items on all pages or items on the currently rendered pages only. To make this choice, specify the selectAllMode property.
- $(function() {
- $("#listContainer").dxList({
- // ...
- selectAllMode: "allPages" // or "page"
- });
- });
See Also
API
Add or remove an item's key from the selectedItemKeys collection to select the item or cancel its selection:
- const list = $("#listContainer").dxList("instance");
- let selectedKeys = list.option("selectedItemKeys");
- // Selects the item with key 5
- selectedKeys.push(5);
- list.option("selectedItemKeys", selectedKeys);
- // Cancels the selection of the item with key 5
- selectedKeys = $.grep(selectedKeys, function(key) {
- return key !== 5;
- });
- list.option("selectedItemKeys", selectedKeys);
See Also
- Call Methods: Angular | Vue | React | jQuery | AngularJS | Knockout
- List Demos
- List API Reference
Events
The List UI component fires the selectionChanged event when an item is selected or when the selection is cancelled. The UI component also fires the selectAllValueChanged event when the "Select All" check box has changed its value. If the functions that handle these events are not going to be changed during the lifetime of the UI component, assign them to the corresponding onEventName properties when you configure the UI component.
- $(function () {
- $("#listContainer").dxList({
- // ...
- onSelectionChanged: function(e) {
- const addedItems = e.addedItems;
- const removedItems = e.removedItems;
- // Handler of the "selectionChanged" event
- },
- onSelectAllValueChanged: function(e) {
- const newCheckBoxValue = e.value;
- // Handler of the "selectAllValueChanged" event
- }
- });
- });
If you are going to change the event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.
- const selectionChangedEventHandler1 = function(e) {
- // First handler of the "selectionChanged" event
- };
- const selectionChangedEventHandler2 = function(e) {
- // Second handler of the "selectionChanged" event
- };
- $("#listContainer").dxList("instance")
- .on("selectionChanged", selectionChangedEventHandler1)
- .on("selectionChanged", selectionChangedEventHandler2);
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.