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 类?
基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
