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

DataSource video example dont work??

2 Answers 88 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Hernan
Top achievements
Rank 1
Hernan asked on 14 May 2012, 05:02 PM
Before my implementation I reproduced your video example about datasource but my example I use local data (http://www.youtube.com/watch?feature=player_embedded&v=FhHMOjN0Bjc)

I need show the id of "DataSource" when select the kendoGrid although the kendoGrid dont show the id in column

var mydata =  [{id:"1",age:"23",name:"hernan"}];  
 
var myschema = kendo.data.Model.define({
        id : "id",
        name: "name",
        age: "age"
    });
 
var ds = new kendo.data.DataSource({
        data: mydata,
        schema : {
            model : myschema
        }
    });
 
//and in the grid I configured it:
var personId;
$("#grid-distributors").kendoGrid({
        dataSource: ds,
        selectable: true,
        height: 360,
        scrollable: true,
        sortable: true,
        pageable: true,
        change : function() {                  
            var id = this.select().data("id");
            personId = this.dataSource.get(id);
            alert(personId);  //DONT SHOW ME THE ID!! :(
        },
        columns: [         
                {
                field: "name",
                title: "Nombre"                
            },
            {
                field: "age",
                title: "Edad"                  
            }
             
        ]
    });


2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 May 2012, 09:57 AM
Hello Hernan,

The Id field is part of the currently selected dataItem. You can retrieve it in the following way:
change: function(e) {
    var tr = this.select(); //gets selected <tr> element
    var item = this.dataItem(tr); //gets the dataSource item
    alert("ID: " + item.id);
}

For convenience I made a small example where you can see this approach in action.
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
Hernan
Top achievements
Rank 1
answered on 15 May 2012, 02:51 PM
Thank you, I also found another way to do it and I want to share in the community 
change : function(e) {
      var uid = this.select().data("uid");
      var selectedRow = ds.getByUid(uid);
      alert("ID: " + selectedRow.get("id") + "NAME: " + selectedRow.get("name"));
}
Tags
Data Source
Asked by
Hernan
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Hernan
Top achievements
Rank 1
Share this question
or