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

Select Page in DataBound event

1 Answer 691 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bertha
Top achievements
Rank 1
Bertha asked on 05 Dec 2012, 08:39 PM
I want when user clciked a link, he can go back to the previous selected page and selected row of kendo grid. I can get his selected page number without problem by

$("#homesGrid").data("kendoGrid").dataSource.page();

In databound event of Kendo Grid, I cannot set his selected page. I can only set his selected row by
$("#homesGrid").data("kendoGrid").dataSource.page(2);   ====> error

var data = mygrid.dataSource.data();
$.each(data,
function (i, row) {
if (row.Fcode == fcode) {
  $(
'tr[data-uid="' + row.uid + '"]').addClass("k-state-selected");
}

Is the code of that line incorrect or is that I cannot set it in databound event of Kendo Grid?

 

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 07 Dec 2012, 12:39 PM
Hello Bertha,

I would not recommend to set the page at the dataBound event because this will create an infinite loop (changing of the page triggers the dataBound event).

You can get the current selected page on the dataBound and re-select the selected row. The re-select implementation depends on what paging is used - client or server side one. The "uid" identifiers are generated on the client side and will change after data is reloaded from the server. This is why it is better to use the id field of the records.

change: function (e) {
  var selectedItem = this.dataItem(this.select()),
      currentPage = this.dataSource.page();
    
  selected[currentPage] = selectedItem.OrderID; //store id in array
},
dataBound: function () {
  var currentPage = this.dataSource.page();
  if(selected[currentPage] !== undefined) {
    var uid = this.dataSource.get(selected[currentPage]).uid; //get the uid
    this.tbody.find("tr[data-uid='" + uid + "']").addClass("k-state-selected"); //re-select the row
  }
}

Please check the following example: http://jsbin.com/itohac/2/edit
I hope this will help.

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