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

Re-select Kendo UI Grid row after .read()

2 Answers 467 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Conor
Top achievements
Rank 1
Conor asked on 28 Apr 2012, 01:05 PM
Hi I am working with the Kendo UI grid and am currently able to display data from my MySQL database using JSON to transport the information.

I am allowing the user to update the data in the database through a series of inputs, which when clicking a row on the grid are populated by an item in the grid's datasource. This is all working perfectly and very quickly. However, when I update the item I am then calling the .read() method on the datasource, and the only issue I am having is that I am not currently able to figure out how I can reselect the same row. I can loop through the datasource's views and find the view in particular that matches up to the edited item by one of its properties but I can't figure out a way to reselect it.

var grid = $(".grid.dynamic.tbl").data("kendoGrid");
grid.dataSource.read();

//console.log(grid.dataSource.view());
for (i in grid.dataSource.view()){
console.log(grid.dataSource.view()[i]);
if (myID == grid.dataSource.view()[i].MyID) console.log('Found correct ID at index: '+i);
}

Any ideas? It is probably staring me right in the face to be honest.

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 02 May 2012, 11:43 AM
Hello Conor,

The grid has a select method that accepts items (rows/cells) and will select the specified elements.
Each record in the dataSource has an unique identified called uid that is attached as a data-uid attribute to its <tr> HTML element. I see that you already found a way to get the view in particular that matches up to the previously selected item, so you could use its uid to find the row and reselect it.
I hope this helps.

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!
0
Basem
Top achievements
Rank 1
answered on 24 May 2012, 04:23 PM
I needed this too. Check out the code I posted in another thread that seems to handle sort, filter, and any other event that forces a re-read on the grid: http://www.kendoui.com/forums/ui/grid/bug-grid-selection-dropping-on-sort.aspx#2122307 
Tags
Data Source
Asked by
Conor
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Basem
Top achievements
Rank 1
Share this question
or