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

Handling Id's / Primary Keys in Grid

1 Answer 325 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boas
Top achievements
Rank 1
Boas asked on 13 Sep 2012, 09:42 AM
Hi

I'mcurrently evaluating the Kendo UI

I load some data from a data service and show the data in the grid.

I have a custom column definition in which i don't show the primary key.

But how can I access the primary key in the change event ?
I can't find something like this in the samples

Can someone help  ?
Below my jscript code


 $(document).ready(function () {
        var apiUrl = '@(Url.RouteUrl("DefaultApi", new { httproute = "", controller = "Inbox" }))';
    
        $("#inboxGrid").kendoGrid({
            change:onSelectionChanged,
            dataSource:
                {
                    transport: { read: apiUrl },
                },
            columns: [
                { title: "SentDate", field: "SentDate", filterable: true, sortable: true, format: "{0:dd.MM.yy}" },
                { title: "Subject", field: "Subject", filterable: true, sortable:false}
            ],          
        });
    });

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 13 Sep 2012, 12:35 PM
Hello Boas,

You may use Grid's dataItem method to get reference to the data record associated with selected Grid row. Then you can access the id field's value:

$("#inboxGrid").kendoGrid({
       selectable: true,
       change: function() {
            var dataItem = this.dataItem(this.select());
            var id = dataItem.productID;
       },
       //...
});

Regards,
Rosen
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
Boas
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or