[英]Get specific column when Kendo Grid row is selected
I'm quite new to Kendo UI and would appreciate if someone could give an advice. 我对Kendo UI相当陌生,如果有人可以提出建议,我将不胜感激。 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: onChange函数:
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. 我需要选择
Number
列的选定值。 Something like $(item[name='Number']).text();
类似于
$(item[name='Number']).text();
I know I could parse the string but I guess there is another way. 我知道我可以解析字符串,但是我想还有另一种方法。
Thanks a lot 非常感谢
You should be using the dataItem
method of the Kendo UI Grid to retrieve the actual data item of the row you selected - reference . 您应该使用Kendo UI Grid的
dataItem
方法检索所选行( 引用的实际数据项)。 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);
}
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.