How to remove CSS class from jqGrid cell?

You can add the CSS class to the jqGrid cell using the setCell method, as shown below.

grid.setCell(rowId, "ColumnName", "", "my-style-class");

Given that this method is only available for adding CSS classes, how can I remove a CSS class from a jqGrid cell?

+5
source share
2 answers

You cannot delete a call class using the standard jqGrid method. So you have to do it manually:

var iCol = getColumnIndexByName(grid,"ColumnName"),
    tr = grid[0].rows.namedItem(rowid), // grid is defined as grid=$("#grid_id")
    td = tr.cells[iCol];
$(td).removeClass("my-style-class");

where getColumnIndexByNameis a simple function that gets the column index by column name:

var getColumnIndexByName = function(grid,columnName) {
    var cm = grid.jqGrid('getGridParam','colModel');
    for (var i=0,l=cm.length; i<l; i++) {
        if (cm[i].name===columnName) {
            return i; // return the index
        }
    }
    return -1;
}

See the demo here .

: jqGrid iColByName, getColumnIndexByName, iColByName jqGrid, .

var p = grid.jqGrid("getGridParam"), // get the reference to all parameters
    iCol = p.iColByName["ColumnName"], // get index by column name
    cm = p.colModel[iCol]; // item of "ColumnName" column

. , jqGrid jqGrid 4.8. GitHub jqGrid 4.9-beta1, .

+11

, :

$("#gridname").removeClass('oldclass')
              .setCell(rowId,'column_name','','newclass');

rowId - id , , :

var ids = $("#gridname").jqGrid('getDataIDs');
+1

All Articles