从服务器加载 jqgrid 结构,不仅是数据

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

是否可以通过 ajax JQGrid 结构(列)与数据一起从服务器加载?如果可能的话,你能举个例子吗?

Is it possible to load from server via ajax JQGrid structure(columns) together with data ? If possible, could you please show an example ?

推荐答案

您可以创建包含所有隐藏列的 jqGrid.您需要创建具有足够多列的网格.列的名称(在 colModel 中)可以有一些通用值,例如 "c1""c2""c3" ...来自服务器的响应可以包含colModel信息和数据.在 beforeProcessing 回调中,您可以更改 colModel 并设置新的列标题.答案演示了动态设置列标题.使用 setLabel 方法简化代码列.另一个答案演示了如何使用setColProp来设置colModel动态完整.如果您将该解决方案与我在 答案 中发布的 setColWidth 方法的使用相结合(请参阅 这里)然后你可以创建完美的解决方案.

You can create jqGrid with all hidden columns. You need create grid with large enough number of columns. The names of the columns (in colModel) can have some generic values like "c1", "c2", "c3" ... The response from the server can contains colModel information together with the data. Inside of beforeProcessing callback you can change colModel and set new column headers. The answer demonstrates setting of column headers dynamically. The code column be simplified by usage setLabel method. Another answer demonstrates how to use setColProp to set the most settings of colModel full dynamically. If you would combine the solution with the usage of setColWidth method which I posted in the answer (see here too) then you could create perfect solution.

相关文章