set colmodel of jqGrid when rows loaded from serve

2019-09-06 12:07发布

问题:

I want to change my grid's colmodel dynamiclly and I did lots of search but non of the question thread answered me. I need to pivot a select in sql so after I execute my query I find out names and count of my grid's columns.

In other posts I find the way of changing the colmodel but I don`t know when and where I must do it. It is not possible to execute query two time becuase It may changed in result and decrease performance.

回答1:

One can use beforeProcessing callback to make many modifications in colModel dynamically. One can't add/remove columns and one can't modify name property, but the most other changes are allowed. I would recommend you to use setColProp method to make the modification. One can use setLabel to modify column headers. The answer, this one and the another one provides corresponding examples.

I am working now on addColumn/removeColumn column methods which will allow to modify colModel more deep. You can find the current beta version of addColumn with the corresponding demos on github.