我的主网格中使用了经验的kendo网格,我的问题是如何从detailInit获取所选行的ID,然后折叠detailInit并将所选数据放入父网格?
我的网格看起来像这样
function TheCatalogGrid(catalogData) {
$("#CatalogGrid").kendoGrid({
dataSource: {
data: catalogData
},
columns: [
{ field: "globalGroupID", title: "Group ID", hidden: true },
{ field: "globalGroupLevel", title: "globalGroupLevel", hidden: true },
{ field: "globalGroupName", title: "Group Name", width:350 },
{ field: "isRequired", title: "*", width:20 },
{ field: "optionName", title: "Option Name" },
{ title: "Description" },
{ title: "Price" }
],
change: function (e) {
onSelectedRowClick();
},
scrollable: true,
pageable: false,
selectable: "row",
height: 500,
dataBound: function (e) {
var data = this.dataSource.data();
$.each(data, function (i, row) {
if (row.get("globalGroupLevel") == 0) {
var element = $('tr[data-uid="' + row.uid + '"] ');
element.addClass("colored-row");
}
});
},
detailInit: detailInit
});
}
我的detailInit看起来像这样
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "//demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
},
},
scrollable: false,
selectable: "row",
columns: [
//{ field: "OrderID", width: "110px" },
{ field: "ShipCountry", title: "Option Name" },
{ field: "ShipAddress", title: "Description" },
{ field: "ShipName", title: "Price" }
]
});
}
将所选数据放入选择网格行的父网格行
我知道列标题没有意义,但在我将其投入生产之前是我的测试。
答案 0 :(得分:0)
您可以使用detailExpand事件来获取主行和id值。
var globalGroupId = null;
detailExpand: function(e) {
console.log(e.masterRow, e.detailRow);
var globalGroupId = e.masterRow.get("globalGroupID");
}
然后为您的细节网格添加更改方法,然后执行操作
change: function(e) {
// get detail row
var detailRow = this.dataItem(this.select());
var shipCountry = detailRow.get("ShipCountry")
// get master row
var masterGrid = $("#grid").getKendoGrid();
var masterRow = masterGrid.dataSource.get(employeeId);
// set 'ship country' value to master row 'Country' field
masterRow.set("Country", shipCountry);
},
看这个Dojo