javascriptjqueryjqxgridjqwidgetjqxwidgets

Finding a row with specific column value in jqxGrid


I am trying to get the data for a row by matching a column value. For example if we have the following data in the grid, I want to get the data of the row which has a CombinedID = 2015-01-02-0222.

[
    {"Name":"Test 1", "CombinedID":"2015-01-02-0111", "Description":"Testing"},

    {"Name":"Test 2", "CombinedID":"2015-01-02-0222", "Description":"Testing 2"},

    {"Name":"Test 2", "CombinedID":"2015-01-02-0333", "Description":"Testing 3"}
]

Cannot find a straight forward method in jqxGrid documentation.

Was looking for something like this (but cannot find any such method yet):

var rowData = $(grid).jqxGrid('getRowByColumnValue','CombinedID',"2015-01-02-0222");

Solution

  • I created a function myself to get the rows which matches the column value:

    function getItemsByColumnValue(grid, field, value, selectField) {
        var rows = $(grid).jqxGrid('getboundrows');
        var output = [];
        rows.forEach(function(row) {
            if(row[field] == value) {
                if(selectField) {
                    //if selectField is specified, put only that field value to array
                    output.push(row[selectField]);
                } else {
                    output.push(row);
                }
            }
        });
        return output;
    }