kendo grid How to get a row by field value
19,501
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.
![pasluc74669](https://i.stack.imgur.com/sNNVr.jpg?s=256&g=1)
Comments
-
pasluc74669 almost 2 years
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]");
-
user2109254 over 10 yearsOnaBai, What about if once you have the record, you then want to also select the corresponding row in the grid? The doco only shows how to select a row by index of the <tr>. How do you do it by primary key?
-
chiapa over 9 yearsHow can I, for example, add a class to the rows that come inside the
res
variable? -
OnaBai over 9 yearsWhat about a template?
-
chiapa over 9 yearsI am using a column template with a checkbox in it. When I click the checkbox, I want to select the row in which the checkbox is. In my javascript, after clicking the checkbox, I manage to get the row model id, but now I want to do something like
row.addClass("k-state-selected");
but I don't know how to make therow
variable the actual grid row (where the clicked checkbox is) -
chiapa over 9 yearsHere is my question, could you please help?
-
Vignesh about 7 yearsPerfect answer @oneBai