Bulk Delete DataGrid Elements
On the client(ts) side of DataGrid, you can delete all of the elements in bulk with the code below in the OnToolbarButtonClick event. The name of the grid and the primary key should be given as variables.
deleteItemInRow = async(gridName: string, docId: any) = ```>``` {
@ts-ignore
const grid = this[gridName];
let documentId: number;
if (grid.rows.length ```>``` 0) {
const filteredRows: Array```<```any```>``` = grid.selectedRowsData.filter((item: any) =```>``` {
return documentId = docId;
});
filteredRows.forEach((item) =```>``` {
this.applyChanges().then(() =```>``` {
let row: any = {
key: documentId,
type: "remove",
data: {}
}
grid.rowChangeAction(row);
});
});
grid.selectedRowKeys = [];
grid.selectedRowsData = [];
grid.reload(true);
}
}
Then we call this function in the OnToolbarButtonClick event.
const grid = this["DataGrid1"];
if (grid.rows.length ```>``` 0) {
grid.selectedRowsData.forEach((item) =```>``` {
this.deleteItemInRow("DataGrid1", item. DOCUMENTID);
});
}