How do I remove a CSS class from a jqGrid cell?(如何从 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 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 jqGrid 单元格中删除 CSS 类?
基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
