Friday, October 5, 2012

highlighting a row in JqGrid based on a column value

function hightlightGridRows(grid, colName, valueToCheck) {     
    var grid_ids = grid.jqGrid('getDataIDs');
    var rowcount = grid_ids.length;
    var columnNames = grid.jqGrid('getGridParam', 'colNames');
    
    $.each(columnNames, function (i, v) {
        columnNames[i] = v.toUpperCase();
    });

    var colNameInUpper = colName.toUpperCase();

    if ($.inArray(colNameInUpper, columnNames) > -1) {
        for (var counter = 0; counter < rowcount; counter++) {
            var rowid = grid_ids[counter];
            var aRow = grid.jqGrid('getRowData', rowid);
            var celldata = grid.getCell(rowid, colName);

            if (celldata == valueToCheck) {
                var trElement = $("#" + rowid, grid);
                trElement.removeClass('ui-widget-content');
                trElement.addClass("gridHighlightRow");
            }
        }
    }
    else {
        alert("Invalid column name to evaluate the condition for highlighting rows in the grid");
    }

}
where
ui-widget-content = It is css class that is applied by default to a JqGrid row.
gridHighlightRow = It is the custom css class to highlight grid row.
References: http://tpeczek.codeplex.com/

No comments:

Post a Comment