有条件地扩展 kendo 网格中的行
Conditionally expand row in kendo grid
在我的 Kendo 网格中,我正在尝试检查我的其中一个列字段是真还是假。如果为真,则应展开行,如果为假,则应保持折叠状态。我对列的代码定义是:
{
field: "Comment",
title: txt.TXT_COMMENT,
template: '<input type="checkbox" #= Comment ? "checked" : "" # disabled="false" ></input>',
},
我在 dataBound 中检查是否有数据的代码条件:
dataBound: function (e) {
var data = this.dataItem;
if (data.Comment == 1) {
this.expandRow(this.tbody.find("tr.k-master-row"));
}
f_OnDataBound(e);
}
感谢您的帮助!
您使用数据绑定事件的方向是正确的。之后您需要做的是遍历所有行并检查特定模型 属性 并扩展或不扩展该特定行。
var grid = $("#grid").data("kendoGrid");
var data = grid.dataSource.data();
var len = data.length;
for(var i = 0; i < len; i++) {
var row = data[i];
if(row.Comment == '1') { // checks for the value of the Comment property
grid.expandRow("tr[data-uid='" + row.uid + "']"); // expands the row with the specific uid
}
}
我对此进行了测试并且运行良好。不过,我不知道 Comment
属性 上有什么,这取决于您在需要时控制和调整 javascript 功能。
编辑
我创建了 a fiddle 来演示上述策略。在示例中,dataBound
函数查找 属性 "name" 并扩展行,如果它是 "Sally"
在我的 Kendo 网格中,我正在尝试检查我的其中一个列字段是真还是假。如果为真,则应展开行,如果为假,则应保持折叠状态。我对列的代码定义是:
{
field: "Comment",
title: txt.TXT_COMMENT,
template: '<input type="checkbox" #= Comment ? "checked" : "" # disabled="false" ></input>',
},
我在 dataBound 中检查是否有数据的代码条件:
dataBound: function (e) {
var data = this.dataItem;
if (data.Comment == 1) {
this.expandRow(this.tbody.find("tr.k-master-row"));
}
f_OnDataBound(e);
}
感谢您的帮助!
您使用数据绑定事件的方向是正确的。之后您需要做的是遍历所有行并检查特定模型 属性 并扩展或不扩展该特定行。
var grid = $("#grid").data("kendoGrid");
var data = grid.dataSource.data();
var len = data.length;
for(var i = 0; i < len; i++) {
var row = data[i];
if(row.Comment == '1') { // checks for the value of the Comment property
grid.expandRow("tr[data-uid='" + row.uid + "']"); // expands the row with the specific uid
}
}
我对此进行了测试并且运行良好。不过,我不知道 Comment
属性 上有什么,这取决于您在需要时控制和调整 javascript 功能。
编辑
我创建了 a fiddle 来演示上述策略。在示例中,dataBound
函数查找 属性 "name" 并扩展行,如果它是 "Sally"