Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a row in kendo grid by data item ID?

I need to select a specific row in kendoGrid but NOT by data-uid (as data-uid is changed when the grid dataSource is loaded again) but by the row itemID. I saw posts but they only select the row by uid which is not what I needed, I actually need to restart the HTML5 application and when grid is loaded, a specific item should be selected. This is what I've been seeing

Demo: jsfiddle.net/rusev/qvKRk/3/

e.g. the object has OrderID as ID, and every time the grid is loaded, it will be the same, unlike uid, I want to know how will I be able to select a row with OrderID, instead of uid.

like image 406
umais Avatar asked Jul 19 '13 07:07

umais


People also ask

What is Pageable in kendo grid?

pageable Boolean|Object (default: false) If set to true the grid will display a pager. By default paging is disabled. Can be set to a JavaScript object which represents the pager configuration. Don't forget to set a pageSize, no matter if paging is performed client-side or server-side.


2 Answers

a work around that I managed to have, was to go through all rows and check which row model has that ID equal to the parameter, and then get that row data-uid and select the item through data-uid. It's working fine for me, since there were no suggestion, it's the better answer for now.

like image 109
umais Avatar answered Oct 27 '22 01:10

umais


Going along with what umais has mentioned, the better approach, since there is no built in functionality for this as of yet, would be to iterate through all the records to find the one you need. The function that I built will work even if there are pages of data. The only other way that I can think of doing this would be do do a secondary ajax call; But this works well. Note that i haven't tested it with more than 2000 records.

    var dataGrid = $("#GATIPS").data("kendoGrid").dataSource;
    var numOfRows = dataGrid.total();
    var currentPageSize = dataGrid.pageSize();
    dataGrid.pageSize(numOfRows);
    var dataGridData = dataGrid.data();
    for (var i = 0; i < numOfRows; i++) {
        if (dataGridData[i].uid == e)
            return dataGridData[i];
    }
    dataGrid.pageSize(currentPageSize); // reset the view

e is the UID. However this can be substituted for what ever variable you need just replace the check.

like image 36
Chance Avatar answered Oct 27 '22 01:10

Chance