ASPxClientGridView.GetSelectedKeysOnPage Method
Returns key values of selected rows displayed within the current page.
Declaration
GetSelectedKeysOnPage(): any[]
Returns
Type | Description |
---|---|
any[] | An array that contains key values of selected rows displayed within the current page. |
Example
This example demonstrates how to use the GetSelectedKeysOnPage
and GetVisibleRowsOnPage methods to prevent a user from deleting all rows on a single grid page (if editing logic requires it).
To do this, you can compare the array length of keys obtained through the client GetSelectedKeysOnPage method (returns keys only on a visible page) and the number of rows on a page obtained through the clientGetVisibleRowsOnPage method.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-manage-row-deletion-on-client-side-t228304
function DeleteSelectedRows(s, e) {
var keys = GridView.GetSelectedKeysOnPage();
var rowsCount = GridView.GetVisibleRowsOnPage();
if (keys.length == rowsCount) {
alert('You cannot delete all rows on a page!');
GridView.UnselectRowsByKey(keys);
} else {
if (confirm('Are you sure you want to delete rows with keys: [' + keys.toString() + ']')) {
alert('Data editing is not allowed in this demo!');
keys.forEach(function (key, index) {
GridView.DeleteRowByKey(key);
});
}
}
};
See Also