This is a migrated thread and some comments may be shown as answers.

Row selection after refreshing grid

1 Answer 373 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shabtai
Top achievements
Rank 1
Shabtai asked on 26 Nov 2013, 04:30 PM
Hello,

I have Kendo selectable Grid being created in razor.
After row is selected user can delete the selected row. But since the grid has multiple pages, after deletion -  reloading contents of data I need the selection to be put on the next row, preserving the current page number...

How can I achieve that?

Thank you for your prompt answer.

Shabtai

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 28 Nov 2013, 09:16 AM
Hi Shabtai,


The selection should be made after the new data is bound. A sample approach would be to store the index of the deleted row and then select the new one in the dataBound event.
E.g.
.Events(e => e.Remove("onRemove").DataBound("dataBound"))
.Selectable()
.DataSource(dataSource => dataSource
    .Ajax()
    .Events(e => e.RequestEnd("requestEnd"))
    ..

var index;
var lastRequest;
 
function onRemove(e) {
    index = e.row.index();
}
 
function requestEnd(e) {
    lastRequest = e.type;
}
 
function dataBound(e) {
    if (lastRequest === "destroy") {
        this.select(this.table.find("tr").eq(index));
 
        //handles the case when the last row was deleted. selects the new last row
        if (this.select().length === 0) {
            this.select(this.table.find("tr:last"));
        }
    }
}

This is a custom solution and I could have missed some case. Feel free to modify the code according to the exact needs.

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Shabtai
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or