0

I want to hide a column or select different width based on the data I am getting on load event but its not working. Here is the code I tried

loadComplete : function(){
            $(this).jqGrid('setColProp', 'ID', {
                hidden: true
            });
        },

but the ID column is still being shown...

coure2011
  • 40,286
  • 83
  • 216
  • 349

2 Answers2

2

try this. Sample fiddle

loadComplete : function()
{
   //Works with new api
   $(this).jqGrid('hideCol',["ID"]); 
   //following works with Older api
   //$(this).hideCol("ID");    
}
Deshan
  • 2,112
  • 25
  • 29
  • Can you point me to documentation of this? I also want to change width, whats the method for that? – coure2011 Jan 29 '15 at 08:38
  • @coure2011: jqGrid 4.6/4.7 don't have any method which allows you to change the column width **dynamically**. *The user* can only use drag & drop of the column resizer (between the headers of two columns). I wrote `setColWidth` method (see `jQuery.jqGrid.setColWidth.js` [here](https://github.com/OlegKi/jqGrid-plugins) and [the answer](http://stackoverflow.com/a/20030652/315935)) which you can use. I'm developing now new *free* version of jqGrid [here](https://github.com/OlegKi/jqGrid). It contains the method and many other new features for resizing of columns. – Oleg Jan 29 '15 at 17:24
1

I'd like to update this after running into the grid not auto resizing to full width after hiding the column. I found adding an inline if statement to the hidden field of the colModel was able to solve both problems.

//before document ready
var fieldEnabled = true;
// in document ready
isFieldEnabled(); // some method to check, that will update `fieldEnabled`
grid.jqGrid({
//Other attributes
colModel:[
   {name: 'ID', 'index': 'ID', hidden: fieldEnabled ? false : true } 
// field enabled is just a boolean that is updated by whatever method you need to check if the column needs to show
]
loadComplete : function(){
//no need for changes here

First answer so I'm prepared to be crucified.

Henry
  • 23
  • 1
  • 4