React List - Selection

User Interaction

In the List UI component, selection is disabled by default. To enable it, choose one of selection modes using the selectionMode property.

App.vue
  • <template>
  • <DxList ...
  • selection-mode="single" /> <!-- or "multiple" | "all" | "none" (disables selection) -->
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxList from 'devextreme-vue/list';
  •  
  • export default {
  • components: {
  • DxList
  • },
  • // ...
  • }
  • </script>

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.

App.vue
  • <template>
  • <DxList ...
  • :show-selection-controls="true"
  • />
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxList from 'devextreme-vue/list';
  •  
  • export default {
  • components: {
  • DxList
  • },
  • // ...
  • }
  • </script>

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.

App.vue
  • <template>
  • <DxList ...
  • select-all-mode="allPages" /> <!-- or "page" -->
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxList from 'devextreme-vue/list';
  •  
  • export default {
  • components: {
  • DxList
  • },
  • // ...
  • }
  • </script>

View Demo

See Also

API

Add or remove an item's key from the selectedItemKeys collection to select the item or cancel its selection:

App.vue
  • <template>
  • <DxList ...
  • v-model:selected-item-keys="selectedKeys"
  • />
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxList from 'devextreme-vue/list';
  •  
  • export default {
  • components: {
  • DxList
  • },
  • data() {
  • return {
  • selectedKeys: [6, 2, 5]
  • }
  • },
  • methods: {
  • selectItem(key) {
  • if(!this.selectedKeys.includes(key)) {
  • this.selectedKeys = [...this.selectedKeys, key];
  • }
  • },
  • deselectItem(key) {
  • this.selectedKeys = this.selectedKeys.filter((data) => {
  • return data !== key;
  • });
  • }
  • }
  • }
  • </script>
NOTE
To specify the key field, use the keyExpr property of the List or the key property of the Store.
See Also

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.

App.vue
  • <template>
  • <DxList ...
  • @selection-changed="onSelectionChanged"
  • @select-all-value-changed="onSelectAllValueChanged"
  • />
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxList from 'devextreme-vue/list';
  •  
  • export default {
  • components: {
  • DxList
  • },
  • // ...
  • methods: {
  • onSelectionChanged (e) {
  • const addedItems = e.addedItems;
  • const removedItems = e.removedItems;
  • // Handler of the "selectionChanged" event
  • },
  • onSelectAllValueChanged (e) {
  • const newCheckBoxValue = e.value;
  • // Handler of the "selectAllValueChanged" event
  • }
  • }
  • }
  • </script>

View Demo

See Also