jqgrid

Select a row in jqGrid based on cell value


colModel: [
            { name: 'Id', index: 'Id', hidden: true, search: false },
            { name: 'Name', index: 'Name', hidden: true, search: false },
          ]

Just as the setSelection method allows selection of a row in jqGrid based on the row number, is it possible to similarly select a row based on one of the cell values.

For e.g. in the colModel above, is it possible to select a row having a certain 'Id' or 'Name' value...assuming that these values are unique for each row.


Solution

  • In the loadComplete: portion of your jqGrid you could iterate over each row and test for the value you are looking for. If the value is found, select the row.

    Ex

    loadComplete: function () {
        var rowIds = $(this).jqGrid('getDataIDs');
    
        for (i = 1; i <= rowIds.length; i++) {
            rowData = $(this).jqGrid('getRowData', i);
    
            if (rowData['Id'] == idSearchValue ) {
               $(this).jqGrid('setSelection',i); 
            } //if
    
        } //for
    ...
    

    There would also be the rowattr: but I can't seem to find where you can get the rowID of the current row. Oleg might see this and respond as well as it was his addition to jqGrid but I didn't have any luck with my testing or read though of where you would get the current rowId to pass to the setSelection method.