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

How to Get Key ID value

1 Answer 491 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 2
Daniel asked on 07 Sep 2012, 09:36 AM
Here below is my code.  How do you get the primay key value.  I can see the correct field in the debugger under
this._data._key.ID=3 this is correct, I just need some help getting that value.  I have searched the forums but couldn't find a working example

Thanks.

function BindData (myArray){
     
         $(document).ready(function() {
 
            $("#grid").kendoGrid({
                dataSource: {
                    data: myArray,
                    pageSize: 10
                },
                   change: onChange,
                selectable: "multiple",
                navigatable: true,
                groupable: true,
                sortable: true,
                pageable: {
                    refresh: true,
                    pageSizes: true
                },
                columns: [ {
                    field: "firstname",
                    width: 90,
                    title: "firstname:"
                },
                {
                    field: "lastname",
                    width: 90,
                    title: "lastname:"
                }                   
                ]
            });
        });
    }
       function onChange(arg) {
                    var selected = $.map(this.select(), function(item) {
                        return $(item).text();
                    });
 ;
 
                     
                    sources.people.select(1)
                  kendoConsole.log("Selected: " + selected.length + " item(s), [" + selected.join(", ") + "]");
     
                }

1 Answer, 1 is accepted

Sort by
0
Accepted
OnaBai
Top achievements
Rank 2
answered on 07 Sep 2012, 10:56 AM
I'm missing some information about your data so I will do some guessing...
Shall I understand that _key.ID is something particular to your "myArray" DataSource?

this is your Kendo Grid, so it is the same than saying $("#grid").data("kendoGrid").
  • To get access to the data source you might use: this.dataSource
  • To access the data: this.dataSource.data() and this returns an array of JSON objects.
  • Assuming that _key and ID are part of your JSON data structure (myArray), then you might just access it as this.dataSource.data()[index]._key.ID

Tags
Grid
Asked by
Daniel
Top achievements
Rank 2
Answers by
OnaBai
Top achievements
Rank 2
Share this question
or