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.

Share:
19,501
pasluc74669
Author by

pasluc74669

Senior Web Developer

Updated on July 29, 2022

Comments

  • pasluc74669
    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
    user2109254 over 10 years
    OnaBai, 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
    chiapa over 9 years
    How can I, for example, add a class to the rows that come inside the res variable?
  • OnaBai
    OnaBai over 9 years
    What about a template?
  • chiapa
    chiapa over 9 years
    I 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 the row variable the actual grid row (where the clicked checkbox is)
  • chiapa
    chiapa over 9 years
    Here is my question, could you please help?
  • Vignesh
    Vignesh about 7 years
    Perfect answer @oneBai