在我的 Kendo 网格中,我试图检查我的列字段之一是 true 还是 false。如果为 true,则行应展开,如果为 false,则行应保持折叠状态。我的列的代码定义是:
{
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);
}
感谢您的帮助!
最佳答案
使用数据绑定(bind)事件,您的方向是正确的。之后您需要做的是,迭代所有行并检查特定的模型属性并展开或不展开该特定行。
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”则展开该行
关于javascript - 有条件地扩展剑道网格中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31385864/