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

Grid Navigation In Kendo

2 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Moshe
Top achievements
Rank 1
Moshe asked on 17 Mar 2020, 02:08 PM

I have a grid which I need to refresh after changing a value in another container. this code is being called from the sync container, now I got it to read and refresh the grid but I want it to keep the current selected row(selected index) but my current code keeps sending it back to 0.

 

function onAssetGridRequestEnd(e) {
    if (e.type == "create")
    {
        //Refresh Grid
        var  grid = $("#ContainerGrid").data("kendoGrid");
        var dataRows = grid.items();
        rowIndex = dataRows.index(grid.select());
         grid.dataSource.read();
        grid.dataSource.sync();
          grid.select(rowIndex);
    }
};

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 19 Mar 2020, 11:12 AM

Hello Moshe,

In the posted code snippet the select method:

grid.select(rowIndex)

is called right after the dataSource read and sync methods, so it will be executed before the Grid is rebound and refreshed, thus the selection won't have any effect. A read request takes time to complete then the Grid is rebound and refreshed, so any row selection should be made at this point.

Here's a dojo example, which shows a possible approach you can use - selecting the row in the dataBound event handler: https://dojo.telerik.com/aJOfopAQ/2

dataBound: function(e) {
  console.log(rowIndex);
  if(rowIndex != "") {
    e.sender.select(e.sender.items()[rowIndex]);
  }
},

In the onAssetGridRequestEnd function, only the read and sync methods are called.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Moshe
Top achievements
Rank 1
answered on 20 Mar 2020, 05:52 AM
This is awesome Ivan thank you.
Tags
Grid
Asked by
Moshe
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Moshe
Top achievements
Rank 1
Share this question
or