Articles in this section
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

Maintain selected index on adding new record

You can find the samples here:

TypeScript sample

JavaScript (ES5) sample

ASP.NET MVC sample

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied