简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM