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

Can't select row in requestEnd event

4 Answers 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 27 May 2014, 06:24 PM
After either creating or saving a record in a kendo grid, I need that record selected so that I can populate (or clear) a couple of child grids.  This code doesn't work:

    function gridJobRequestEnd(e) {<br>        if (e.type == "update" && e.response.Data != null) {<br>            var gridJob = $("#gridJob").data("kendoGrid");<br>            var job = gridJob.dataSource.get(e.response.Data[0].JobKey);<br>            var tr = $("[data-uid='" + job.uid + "']", gridJob.tbody);<br>            gridJob.select(tr);<br>        }<br>    }

I have verifed (using alerts) that the JobKey is as expected and "tr" is a valid row.  However the row is never selected.  Is there another way to do this?

4 Answers, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 27 May 2014, 06:31 PM
Sorry here is the formatted code:

function gridJobRequestEnd(e) {
    if (e.type == "update" && e.response.Data != null) {
        var gridJob = $("#gridJob").data("kendoGrid");
        var job = gridJob.dataSource.get(e.response.Data[0].JobKey);
        var tr = $("[data-uid='" + job.uid + "']", gridJob.tbody);
        gridJob.select(tr);
    }
}
0
Accepted
Dimiter Madjarov
Telerik team
answered on 28 May 2014, 11:06 AM
Hi Bob,


Indeed the row will be existing in the Grid and will be selected in the requestEnd event handler. Nevertheless when the new data is bound afterwards, all Grid rows will be redrawn, which is causing the selection to be lost. This is why I would suggest you to use the requestEnd event handler to store the uid of the row to be selected and then select it in the dataBound event handler, in which the newly redrawn rows will be accessible.

Let me know if this information helps or I could assist further.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bob
Top achievements
Rank 1
answered on 28 May 2014, 11:12 AM
That worked perfectly.  Here is the code I used for anyone who needs to do this in the future:

var uid = null;
 
function gridJobRequestEnd(e) {
    if (e.type == "update" && e.response.Data != null) {
        var gridJob = $("#gridJob").data("kendoGrid");
        var job = gridJob.dataSource.get(e.response.Data[0].JobKey);
        uid = job.uid;
    }
}
 
function gridJobLoaded(e) {
    if (uid != null) {
        var gridJob = $("#gridJob").data("kendoGrid");
        var tr = $("[data-uid='" + uid + "']", gridJob.tbody);
        gridJob.select(tr);
    }
}
0
Dimiter Madjarov
Telerik team
answered on 28 May 2014, 11:16 AM
Hello Bob,


I am glad the information was helpful. This is the correct approach to achieve this.

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
Bob
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or