kendo grid如何按字段值获取行

时间:2013-10-09 16:00:04

标签: javascript kendo-ui kendo-grid

我需要从我的kendo网格中获取一行,使用字符串作为参数来过滤行。 网格模型是:

{
    id: "id_tipo_pagamento",
    fields: {
        id_tipo_pagamento: { type: "number", editable: false },
        desc_tipo_pagamento: { type: "string"}
}

我试过这个,但是没有用:

 var grid = $("#kendoGrid").data("kendoGrid");
 var row = grid.tbody.find("tr[desc_tipo_pagamento=test]");

1 个答案:

答案 0 :(得分:17)

我建议您不要使用DOM,而是建议jQuery.grep数组使用DataSource.data(如果需要全部),或者DataSource.view使用当前可见的数据。

示例:

// Retrieve all data from the DataSource
var data = grid.dataSource.data();
// Find those records that have desc_tipo_pagamento set to "test"
// and return them in `res` array
var res = $.grep(data, function (d) {
    return d.desc_tipo_pagamento == "test";
});

res将包含对DataSource中与条件匹配的记录的引用。