Kendo网格行选择

时间:2012-02-03 15:12:26

标签: php javascript kendo-ui

如何通过点击获取行ID?实际上我想将远程表的行ID分配给网格的每一行,通过点击它,我想加载第二个网格。任何解决方案?

2 个答案:

答案 0 :(得分:5)

在这里你http://jsfiddle.net/qvKRk/

<强>的JavaScript

var dataSample = [];
dataSample.push({
    OrderID: "1",
    ShipName: "line 1"
});
dataSample.push({
    OrderID: "2",
    ShipName: "line 2"
});
dataSample.push({
    OrderID: "3",
    ShipName: "line 3"
});

var dataSource = new kendo.data.DataSource({
    data: dataSample,
    schema: {
        model: {
            id: "OrderID"
        }
    },
    pageSize: 10
});

$("#grid").kendoGrid({
    dataSource: dataSource,
    selectable: true,
    columns: ["OrderID", "ShipName"],
    change: function () {
        var row = this.select();
        var id = row.data("id");
        $("#log").html("selected row with id= " + id);
        // sample selecting same row on second grid 
        // based on this post
        var secondGrid = $("#grid2").data("kendoGrid");
        var row = secondGrid.table.find('tr[data-id="' + id + '"]');
        secondGrid.select(row);
    }
});

$("#grid2").kendoGrid({
    dataSource: dataSource,
    selectable: true,
    columns: ["OrderID", "ShipName"]
});

<强> HTML

master grid :
<br />
<div id="grid"></div>
<div id="log"></div>child grid :
<br />
<div id="grid2"></div>

答案 1 :(得分:0)

var grid = $("#GridSearchResults").data("kendoGrid");
var cel;

grid.select().each(function() {
var dataItem = grid.dataItem($(this));
cel = dataItem.InventoryItemId;
});

单元格将包含您选择行后要提取的列。 注意:确保在网格中启用选择。