javascript 剑道网格如何按字段值获取一行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19276994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:58:13  来源:igfitidea点击:

kendo grid How to get a row by field value

javascriptkendo-uikendo-grid

提问by pasluc74669

I need to get a row(s) from my kendo grid, using a string as parameter to filter rows. the grid model is:

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

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

i tried this, but isn't working:

我试过这个,但不起作用:

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

回答by OnaBai

Instead of using DOM, I would suggest using jQuery.grepon the DataSource.dataarray (if you want all) or in DataSource.viewif you want from the current visible ones.

我建议不要使用 DOM,而是建议jQuery.grepDataSource.data数组上使用(如果你想要全部),或者DataSource.view如果你想要从当前可见的数组中使用。

Example:

例子:

// 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";
});

reswill contain a reference to the records in DataSource that matched the condition.

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