javascript - 有条件地扩展剑道网格中的行

标签 javascript jquery kendo-ui kendo-grid

在我的 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/

相关文章:

javascript - 如何将文件内容转换成字符串?

javascript - 为什么我不能使用 onClick 来执行 jQuery $(document).ready 函数内的函数?

javascript - 在 Kendo MaskedTextBox 中应用正则表达式

javascript - 每 6 小时 cron 模式不适用于 Nodejs cron

javascript - 在 React 中处理图像加载

javascript - req.session 仅在 AJAX 中未定义

javascript - 如何对 Excel 电子表格进行排序 (KENDO UI)

javascript - 使用 Knockout-Kendo.js 库刷新 KendoDropDown

javascript - 为什么我使用 JavaScript 的点导航不起作用。 (不会跳转到页面上的部分)

javascript - 如果某个单元格不为空,如何更改 Slickgrid 中的行背景颜色?