Javascript jqGrid 添加新列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4232038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:30:10  来源:igfitidea点击:

jqGrid add new column

javascriptjqueryjqgrid

提问by Max Frai

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.

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

回答by Oleg

It is not possible to add a column to the jqGrid dynamically. You have to recreate the whole grid with colModelhaving one column more. If you use separate colNames, then the size of the array have to be increased too. You can use GridDestroyfor example to destroy the existing grid. The usage of jQuery.Removeor jQuery.Emptyinstead is also possible.

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

UPDATED: It seems to me that GridUnloadis better for your porpose. I created small demowhich demonstrate how one can recreate a grid. To be able to use GridUnloador GridDestroyyou 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 downloadpage.

更新:在我看来GridUnload更适合你的姿势。我创建了一个小演示来演示如何重新创建网格。为了能够使用GridUnloadGridDestroy,您必须验证您的项目中是否包含 grid.custom.js(如果您使用 jqGrid 的开发人员版本),或者您已在jqGrid 下载页面上选中“自定义”“附加方法” 。

UPDATED 2: One can use addColumnmethod 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.htmexamples).

更新 2:可以使用addColumn可以从这里下载的方法(请参阅 参考资料jQuery.jqGrid.addColumn.js)。该方法仍处于测试阶段。人们可以找到一些演示展示了如何使用该方法,在这里(见addColumnX.htm例子)。

回答by hiten shah

just use

只是使用

$("#gridid").jqGrid('GridUnload');

it will unload grid totally and will be ready to load again with new columns and data.

它将完全卸载网格,并准备好再次加载新的列和数据。

回答by Kshitiz Singh

rownumbers: true, and rownumWidth:25(default)

rownumbers: true, and rownumWidth:25(default)

回答by Donald Taylor

You can simply set the new column model and reload the grid:

您可以简单地设置新的列模型并重新加载网格:

var newColModel = $("#myGrid").jqGrid("getGridParam", "colModel").concat({ /* new column attributes */ });
$("#myGrid").jqGrid("setGridParam", {colModel: newColModel}).trigger("reloadGrid");