Category / Section
How to maintain selected rows after adding new record
1 min read
When a new row is added in the grid, the grid gets refreshed and the previously selected index will not be maintained as the newly added row was in the selected state.
However, the previous selection can be maintained by storing the selected index in the actionBegin event on add request type, and then selecting the stored indexes using the selectRow method in the actionComplete event.
var selectedIndex; // Grid’s actionBegin event function function onActionBegin(args) { if (args.requestType === 'add') { // Store the selected indexes selectedIndex = this.getSelectedRowIndexes(); } } // Grid’s actionComplete event function function onActionComplete(args) { if (args.requestType === 'save') { var i = 0; while (i < selectedIndex.length) { // Select the next index from the stored one considering the newly added record this.selectRow(selectedIndex[i] + 1); i++; } selectedIndex = []; } }
Note:
You can also use the selectRows method to select a collection of rows using their indexes.
Output
You can find the samples here: