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

On document ready, setting Kendo grid.select by data-uid does not work

4 Answers 585 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gavin
Top achievements
Rank 1
Gavin asked on 15 Nov 2012, 06:23 PM
Hi. I am trying to have the Kendo UI grid select an initial row by ID that I specify. In the following code, grid.select(row) using the data-uid selector does not work. This same code works perfectly fine once the grid is 'up and running'. However, grid.select(row1) using the first row selector DOES work. What is the difference?

I am using Ajax binding if that makes any difference, but the view (page) is initially displayed in response to a HTTP Get MVC action. I also tried initializing in the DataBound event, but same problem.

    $(document).ready(function () {
        // Get a reference to the grid
        var grid = $("#Grid").data("kendoGrid");

        // Select row if specified
        if (dataTypeSelectedGuid) {

            // This snippet does not work - grid.select() returns no rows
            // AND yes, dataTypeSelectedGuid is correct and valid when
            // I look at the HTML.
            var guidRowMatch = "tr[data-uid=" + dataTypeSelectedGuid + "]";
            var row = grid.tbody.find(guidRowMatch);
            grid.select(row);
            var select = grid.select();
            var dataType = grid.dataItem(select);

            // This snippet does work - grid.select() returns first row
            // as expected. What gives? What's the difference?
            var guidRowMatch1 = ">tr:first";
            var row1 = grid.tbody.find(guidRowMatch1);
            grid.select(row1);
            var select1 = grid.select();
            var dataType1 = grid.dataItem(select1);
        }
    });

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 16 Nov 2012, 08:03 AM
Hello Gavin,

Selecting an item will work only if the Grid is already bound. You can see it working here: http://demos.kendoui.com/web/grid/api.html

Greetings,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jacques
Top achievements
Rank 2
answered on 15 Jan 2014, 05:39 AM
Hi Nikolay, 

The example you specify is valid and works, but if you want to use the Grid/DataSource unique ID to select a row the use of find("tr[data-uid...]") doesn't seem to work.

Regards,
Jacques
0
Nikolay Rusev
Telerik team
answered on 17 Jan 2014, 08:33 AM
Hello Jacques,

If you have the item `uid` you can use it to find the table row and select it. Here is an example for this: http://jsbin.com/eNEPUKA/1/edit

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jacques
Top achievements
Rank 2
answered on 17 Jan 2014, 08:59 AM
Thanks Nikolay, I actually managed to resolve this in another post. 

We figured out that when you make use of row templates, you have to explicitly create the data-uid attribute yourself and bind to the uid property of the dataItem. 

Regards,
Jacques
Tags
Grid
Asked by
Gavin
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Jacques
Top achievements
Rank 2
Share this question
or