1

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

1 Answers1

2

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;
}
  • 1
    Thanks for answering your own question, I was looking into the best way to do this and your way works. The only thing I'm trying to do now is retrieve the row index for these results so I can use them programmatically, any idea? – TravisO Jan 04 '18 at 19:20
  • 1
    @TravisO the rowdata has fields called `boundindex` and `visibleindex`. You can get it by calling like this : `getItemsByColumnValue(grid, field, value,'boundindex');` – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 05 '18 at 06:08