0

我正在 MasterGrid 中构建一个 ChildGrid。在子网格中,我向每一行添加了一个复选框模板。childgrid复选框的OnSelect,它调用一个函数。任何人都可以帮助我在检查 childgrid 复选框时获取 childgrid 行的详细信息。

提前致谢

$("#grid").kendoGrid({

   dataSource: {
            data: jdata,
            schema: gridschema,
            pageSize: 10
    },
    pageable:   true,
    detailInit: GetEvents,
    selectable: 'multiple',
    columns: column,
    editable: { mode: "popup" },
    scrollable: true,
    width:1250
});

function GetEvents(e)
{  

var schema=  { 
       model:  {
        id: "Type",
        fields: {
            Type: { editable: false, nullable: true },
            Date: { type: "date" }        
        }
    }
};
try
{
    dataSource = new kendo.data.DataSource({
        transport: {
            read:function (options) {
                jQuery.support.cors = true;
                 $.ajax(
                 {
                     url: serviceURL ,
                     type: "POST",
                     dataType: "json",
                     data:jsonString,
                     contentType: "application/json; charset=utf-8",
                     success: function (data) {
                         var res=   jQuery.parseJSON(data.d)  ;                            
                         options.success(res.events);
                     } ,
                     error: function (d,status,error) { alert(d,status,error); }
                 });
            }
        },
        batch: true,
        schema: schema,
        filter: { field: "Type", operator: "eq", value: e.data.Type },
        pageSize: 5

    });
    GetEventsByBreachchildGrid=   $('<div/>').appendTo(e.detailCell).kendoGrid({
        dataSource:dataSource   ,
        pageable: {
            refresh: true,
            pageSizes: true
        },
        selectable: 'multiple',
        columns:  [
            { field: "Date", title: " Date & Time",template: '#=                     kendo.toString(Date,"dd/MM/yyyy h:mm:ss tt") #', width: "350px" },
            { field: "Type", title:"Event Type"},
            {title:"Action", template: '<input class="events"  id="${id}" type="checkbox" onclick="Test()"/>',  width: 70 }],
        scrollable: false,
        sortable: true
    }).data("kendoGrid");
4

1 回答 1

0

首先,您需要更改模板以Test使用参数调用函数this。像这样的东西:

template: '<input class="events" id="${id}" type="checkbox" onclick="Test(this)"/>',

然后你需要将Test函数定义为全局的(否则你点击的时候会找不到)。这个函数类似于:

function Test(me) {
    // me is the input
    console.log("Test", me);
    // row is the tr containing all the record.
    var row = $(me).closest("tr");
    console.log("row", row);
    // Lets find the grid, since we do not have an id we find the closest grid (class k-grid)
    var grid = $(row).closest(".k-grid").data("kendoGrid");
    console.log("grid", grid);
    // And finally get the item data
    var item = grid.dataItem(row);
    console.log("item", item);
}
于 2013-05-08T12:16:23.257 回答