如何从jqGrid单元格中删除CSS类? [英] How do I remove a CSS class from a jqGrid cell?

查看:127
本文介绍了如何从jqGrid单元格中删除CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用setCell方法将CSS类添加到jqGrid单元中.

It is possible to add a CSS class to a jqGrid cell using the setCell method as below.

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

考虑到此方法似乎只能添加 CSS类,如何从jqGrid单元中删除 CSS类?

Considering that this method appears only able to add CSS classes, how can one remove a CSS class from a jqGrid cell?

推荐答案

无法使用标准jqGrid方法删除调用类.因此,您必须手动执行此操作:

One can't remove the call class with a standard jqGrid method. So you have to do this 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");

其中getColumnIndexByName是一个简单函数,可通过列名获取列索引:

where getColumnIndexByName is a simple function which get the column index by the 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;
}

此处中查看演示.

更新:免费jqGrid 具有iColByName内部参数可以代替getColumnIndexByName功能使用. iColByName参数将由内部的免费jqGrid填充,并将通过重新编排列进行更新.因此,使用

UPDATED: Free jqGrid have iColByName internal parameter which can be used instead of getColumnIndexByName function. The iColByName parameter will be filled by free jqGrid internally and it will updated by reodering of columns. So it's safe to use

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 4.8发布之后,免费jqGrid 中包含了该功能.因此,必须从GitHub下载最新资源或至少使用免费的jqGrid 4.9-beta1才能具有此功能.

The way is very simple and it works very quickly. One should take in consideration that the feature is included in free jqGrid after publishing of free jqGrid 4.8. So one have to download the latest sources from GitHub or to use at least free jqGrid 4.9-beta1 to have the feature.

这篇关于如何从jqGrid单元格中删除CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆