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

Pass a value to something else onChange

6 Answers 1033 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
sitefinitysteve asked on 23 Aug 2011, 09:49 PM
In the OnChange event, I need to pass the "datakey" (for a lack of a better word) to another object.  Problem is the ID field isn't actually visible in the grid...

Suggestions?...is there a way to do a hidden column?

6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 24 Aug 2011, 01:08 PM
Hi Steve,

You may use the dataSource's view to get the dataItem. Please take a look at this jsfiddle test page.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 24 Aug 2011, 02:07 PM
Hmmm, my grid isn't populated via the DS component though...what would I do in that case?

Like I could ALSO have a hidden column with the IDs and just to find the selected element with jQuery?...but no hidden columsn?
0
Accepted
Rosen
Telerik team
answered on 24 Aug 2011, 02:41 PM
Steve,

Did you get a chance  to look at the link I have provided in my previous message? As you may know there is always a dataSource within the grid, even if you did not explicitly provide one.

Indeed, currently there are not  hidden columns. Hidden column is not needed in this case as the entire data item is available.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 24 Aug 2011, 03:06 PM
AH ha!  I was doing it wrong, but yes indeed this now works and the entire dataitem being there is very very nice indeed

Thanks much!

$("#mediaitems").kendoGrid({
                               dataSource: data.mediaitems,
                               scrollable: true,
                               selectable: true,
                               sortable: true,
                               pageable: false,
                               change: function (e) {
                                   var dataItem = this.dataSource.view()[this.select().index()];
                                   alert(dataItem.nodeid);
                               },
                               columns: [
                                   { field: "rating", title: "Rating", width: "100px" },
                                   { field: "title", title: "Title" },
                                   { field: "speaker", title: "Speaker" },
                                   { field: "date", title: "Created", width: "200px", template: '<#= kendo.toString(date,"dd MMMM yyyy") #>' },
                                   { field: "nodeid", title: "Actions", width: "100px", template: '<a class="videolink" href="http://media.dev123.medportal.ca/kendosearch.aspx?id=<;#= nodeid #>">link to video </a>' }
                               ]
                           }
);
0
Voss
Top achievements
Rank 1
answered on 29 Nov 2011, 09:47 PM
this.dataSource.view()[this.select().closest("tr").index()];
this.dataSource.view()[this.select().index()];

Whats the difference in the code above. I've seen both given as examples of extracting the selected data item from a grid?
0
Rosen
Telerik team
answered on 30 Nov 2011, 08:21 AM
Hello Voss,

Both approaches are valid, however it depends on the selection mode. The first should be used if cell selection is used and the second one can be used if row selection is enabled.

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
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Rosen
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Voss
Top achievements
Rank 1
Share this question
or