User Interaction
To allow the user to delete items from the List, set the allowItemDeleting property to true. The mode in which the user deletes items depends on the value of the itemDeleteMode property. There are several modes that are enumerated in the code below. To spot the difference between them and choose the most suitable one, refer to the example that completes the property's description in the API reference.
- <template>
- <DxList ...
- :allow-item-deleting="true"
- item-delete-mode="toggle"> <!-- or "static" | "slideButton" | "slideItem" | "swipe" | "context" -->
- </DxList>
- </template>
- <script>
- import 'devextreme/dist/css/dx.light.css';
- import DxList from 'devextreme-vue/list';
- export default {
- components: {
- DxList
- },
- // ...
- }
- </script>
See Also
API
You can delete a list item by its index. Pass the index to the deleteItem(itemIndex) method. If the List is grouped, this method should be given an object with the indexes of the group and the item to be deleted.
- <template>
- <DxList ...
- :ref="listRefKey"
- />
- </template>
- <script>
- import 'devextreme/dist/css/dx.light.css';
- import DxList from 'devextreme-vue/list';
- const listRefKey = "my-list";
- // ...
- export default {
- components: {
- DxList
- },
- data() {
- return {
- // ...
- listRefKey
- }
- },
- methods: {
- deleteItem (index) {
- this.list.deleteItem(index);
- },
- deleteItemFromGroup (itemIndex, groupIndex) {
- // Delete an item with `itemIndex` from a group with `groupIndex`
- this.list.deleteItem({ group: groupIndex, item: itemIndex });
- }
- },
- computed: {
- list: function() {
- return this.$refs[listRefKey].instance;
- }
- }
- }
- </script>
See Also
Events
To execute certain commands before or after an item is deleted from the List, handle the itemDeleting or itemDeleted event. If the functions that handle these events are not going to be changed during the lifetime of the UI component, assign them to the onEventName property when you configure the UI component.
- <template>
- <DxList ...
- @item-deleting="onItemDeleting"
- @item-deleted="onItemDeleted">
- <!-- ... -->
- </DxList>
- </template>
- <script>
- import 'devextreme/dist/css/dx.light.css';
- import DxList from 'devextreme-vue/list';
- export default {
- components: {
- DxList
- },
- // ...
- methods: {
- onItemDeleting (e) {
- const itemData = e.itemData;
- const itemDomNode = e.itemElement;
- const itemIndex = e.itemIndex;
- // Handler of the "itemDeleting" event
- },
- onItemDeleted (e) {
- const itemData = e.itemData;
- const itemDomNode = e.itemElement;
- const itemIndex = e.itemIndex;
- // Handler of the "itemDeleted" event
- }
- }
- }
- </script>
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.