JqGrid - setting header dynamically

I have a caption parameter set in jqGrid definition. I want to know if there is a way to set it dynamically depending on the class attribute of the table element to which the jqGrid plugin is connected.

HTML 1

 <table id="myjqgrid" class="view"></table> <div id="Pager"></div> 

HTML 2

 <table id="myjqgrid" class="edit"></table> <div id="Pager"></div> 

JQGrid Definition

 $("#myjqgrid").jqGrid({ caption: "" // this is what I want to set dynamically }) 
+7
source share
1 answer

You can use setCaption to set a new header in the grid:

 var $grid = $('#myjqgrid'); $grid.jqGrid('setCaption', 'newCaption'); 

If you need to set the label depending on the class of the <table> element, the code may look like this:

 if ($grid.hasClass('edit')) { $grid.jqGrid('setCaption', 'Edit Caption'); } else if ($grid.hasClass('vew')) { $grid.jqGrid('setCaption', 'View Caption'); } else { $grid.jqGrid('setCaption', 'Default Caption'); } 

The only thing you cannot do with the setCaption method is to remove (to hide) the signature: the results, which if you created a grid without the caption parameter (or using caption: "" ). To remove (to hide) the title, you can do

 $(">div.ui-jqgrid-titlebar", $grid.closest('div.ui-jqgrid-view')).hide(); 

or

 $($grid[0].grid.cDiv).hide(); 

(see details).

+14
source

All Articles