pasluc74669 pasluc74669 - 19 days ago 6
Javascript Question

kendo grid How to get a row by field value

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]");

Answer

Instead of using DOM, I would suggest using jQuery.grep on the DataSource.data array (if you want all) or in DataSource.view if you want from the current visible ones.

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

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

Comments