在行单击中打开详细信息 - kendo grid

时间:2013-11-13 08:24:30

标签: kendo-ui kendo-grid

我在ASP.NET MVC4项目中使用Kendo UI web 我正在尝试为每个创建一个主/细节网格和一个detailsTemplate。我对这种情况有一些疑问:
层次结构和细节之间有什么区别?
是否可以在主行点击而不是那个小三角形的单独div中填充细节网格?
这段代码是我的出发点:http://jsfiddle.net/WKSkC/2/

var element = $("#grid").kendoGrid({
dataSource: {
    type: "odata",
    transport: {
        read: "http://demos.kendoui.com/service/Northwind.svc/Employees"
    },
    pageSize: 6,
    serverPaging: true,
    serverSorting: true
},
height: 430,
sortable: true,
pageable: true,
detailInit: detailInit,
dataBound: function () {
    this.expandRow(this.tbody.find("tr.k-master-row").first());
},
columns:
        [
            {field: "FirstName", title: "First Name", width: "110px" },
            { field: "LastName", title: "Last Name", width: "110px" },
            { field: "Country", width: "110px" },
            { field: "City", width: "110px" },
            { field: "Title" }
        ]});

function detailInit(e) {
  $("<div/>").appendTo(e.detailCell).kendoGrid({
    dataSource: {
        type: "odata",
        transport: {
            read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
        },
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        pageSize: 5,
        filter: { field: "EmployeeID", operator: "eq", value: e.data.EmployeeID }
    },
    scrollable: false,
    sortable: false,
    selectable: true,
    pageable: true,
    columns:
            [
                { field: "OrderID", width: "70px" },
                { field: "ShipCountry", title: "Ship Country", width: "110px" },
                { field: "ShipAddress", title: "Ship Address" },
                { field: "ShipName", title: "Ship Name", width: "200px" }
            ]
  }).data("kendoGrid");
 }

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您可以使用Grid的API以编程方式展开它。

//you can expand it programatically using the expandRow like this
element.on('click','tr',function(){
   $(element).data().kendoGrid.expandRow($(this));
})

这是updated版本。

或者你可以使用make grid来选择并使用select事件而不是挂钩如上所示的点击事件。

相关问题