Get specific column when Kendo Grid row is selected
-
21-12-2019 - |
Question
I'm quite new to Kendo UI and would appreciate if someone could give an advice. I need to get a value of specific column when my grid row is selected. Till now I can get the values of all columns of selected row:
$("#grid").kendoGrid({
...
change:onChange,
columns: [{
field: "Number",
title: 'Number',
}, {
field: "Title",
title: "Title",
}]
});
onChange function:
function onChange(arg) {
var selected = $.map(this.select(), function (item) {
return $(item).text();
});
alert(selected);
}
I need to take the selected value of Number
column. Something like $(item[name='Number']).text();
I know I could parse the string but I guess there is another way.
Thanks a lot
Solution
You should be using the dataItem
method of the Kendo UI Grid to retrieve the actual data item of the row you selected - reference. Then, you can retrieve the value you need by property name.
function onChange(e) {
var selected = this.select()[0],
item = this.dataItem(selected);
alert(item.Number);
}
OTHER TIPS
if you have multiple selection and want to collect first column of all selected row. use following code
var allSelected = "";
var selectedRows = this.select();
for (i = 0; i < selectedRows.length ; i++) {
allSelected = allSelected + ", " + this.dataItem(selectedRows[i]).task_number;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow