我想检查网格行在子表/网格中是否有相关记录。我尝试在父网格的数据绑定事件中挂钩子网格的数据源。这两个网格由ParentId列(这是父网格的主键)绑定。在父网格的数据绑定事件中,如何首先将所有数据从子表中读取到datasource1中,以便以后可以用来搜索父网格行的子项?
Grid_OnDataBound = function (e) {
var dataSource1 = new kendo.data.DataSource({
serverFiltering: false,
transport: {
read: {
/* omitted for brevity */
dataType: "json",
url: "@Url.Action("Items_Read", "Home")"
}
}
});
dataSource1.read();
// get the root grid
var grid = $("#parent_grid").getKendoGrid();
// get its data source
var dataSource = grid.dataSource;
var items = e.sender.items(); // get all rows
items.each(function () {
var row = $(this);
var dataItem = e.sender.dataItem(row);
var parentId = dataItem.ParentId;
var children = new kendo.data.DataSource({
data: dataSource1.data(),
// filter to leave only the child items
filter: {
field: "ParentId",
operator: "eq",
value: parentId
}
});
children.read();
// check if there are any child items
if (children.view().length == 0) {
row.find(".k-hierarchy-cell").html("");
}
})
};