jqGrid 添加新列

2022-01-19 00:00:00 jquery javascript jqgrid

我发现在 JQuery 的 jqGrid 插件中我可以动态添加行,但是我可以对列做同样的事情吗?如果有一个简单的表格,我更愿意手动手动完成,但是 jqGrid 将表格信息存储在很多 div 中.

I found that in jqGrid plugin for JQuery I can add rows dynamically, but can I do the same with columns? If there would be a simple table I'd prefer to do this manually by hands, but jqGrid stores table information in a lot of divs.

推荐答案

无法动态添加列到jqGrid.您必须使用 colModel 重新创建整个网格,其中包含一列.如果你使用单独的 colNames,那么数组的大小也必须增加.例如,您可以使用 GridDestroy 来销毁现有网格.也可以使用 jQuery.RemovejQuery.Empty 代替.

It is not possible to add a column to the jqGrid dynamically. You have to recreate the whole grid with colModel having one column more. If you use separate colNames, then the size of the array have to be increased too. You can use GridDestroy for example to destroy the existing grid. The usage of jQuery.Remove or jQuery.Empty instead is also possible.

更新:在我看来,GridUnload 更适合您的建议.我创建了 小型演示,它演示了如何重新创建网格.为了能够使用 GridUnload 或 GridDestroy 你必须确认你在你的项目(如果您使用 jqGrid 的开发人员版本)或者您已在 jqGrid 下载 页面.

UPDATED: It seems to me that GridUnload is better for your porpose. I created small demo which demonstrate how one can recreate a grid. To be able to use GridUnload or GridDestroy you have to verify that you include grid.custom.js in your project (if you use developer version of the jqGrid) or you have checked "Custom" "Additinal methods" on the jqGrid download page.

UPDATED 2:可以使用 addColumn 方法,该方法可以从 这里(参见 jQuery.jqGrid.addColumn.js).该方法仍处于测试阶段.您可以在 here 找到一些演示如何使用该方法(参见addColumnX.htm 示例).

UPDATED 2: One can use addColumn method which can be downloaded from here (see jQuery.jqGrid.addColumn.js). The method is still in beta phase. One can find some demos which shows how to use the method here (see addColumnX.htm examples).

相关文章