Deleting or recovering an item

Home > Basic examples > Example 05

Explanation

Items can be deleted using delete key and delete function.

Select a target in the component and press the delete key on the keyboard to delete it.

Alternatively, you can call the function in the script to delete the selected, checked or all.

If you want to delete all, delete selected, or delete checked, you can bind automatically using the btnDeleteAll, btnDeleteSelected and btnDeleteChecked properties in the dx5.create function.

<button id="btn-delete-all">Delete all</button>
<button id="btn-delete-selected">Delete selected</button>
<button id="btn-delete-checked">Delete checked</button>
<script>
	dx5.create({
		...
		// Linking buttons
		btnDeleteAll: "btn-delete-all", btnDeleteSelected: "btn-delete-selected", btnDeleteChecked: "btn-delete-checked"
	});
</script>

When a file is deleted by the delete key, a delete event is raised and the associated callback function is called.

For onDX5BeforeItemsDelete and onDX5ItemDeleting callback functions, if the return value is false, the operation is canceled.

// Called before deleting.
function onDX5BeforeItemsDelete(id, arr) {
	// arr is an array of item IDs to delete.
	return confirm("Are you sure you want to delete " + arr.length + " item(s)?");
}

// Called before individual deletion.
function onDX5ItemDeleting(id, itemId) {
	var item = dx5.get(id).getItemById(itemId);
	return confirm(""Are you sure you want to delete the '" + item.name + "' item?");
}

// Called when deletion is complete.
function onDX5ItemsDeleted(id, count) {
	alert(count > 0 ? count + " item(s) deleted." : "No items deleted.");
}

Unlike local files, if a virtual file is deleted, it is not removed immediately but remains inside.

The deleted virtual file can be identified by using the getRemovedFiles function. If necessary, it can be recovered by using the revokeAllVirtualFiles function.

Example

The following buttons delete items using automatic binding.

The virtual file is not deleted immediately, but is kept deleted.