views:

126

answers:

2

I have a jqGrid column which name may change (is a variable), how do I get the name and hide it?

Something along the lines of the below (which don't work)

 $('#tblGridName').jqGrid('hideCol',4);

or

var infoName = $('.ui-jqgrid-htable th:eq(4)').text();
$('#tblGridName').jqGrid('hideCol',infoName );
A: 

Sorry, found the answer almost right off.

Just amended this

var infoName = $('.ui-jqgrid-htable th:eq(4)').text();
$('#tblGridName').jqGrid('hideCol',infoName );

to be

var infoName = $.trim( $('.ui-jqgrid-htable th:eq(4)').text() );
$('#tblGridName').jqGrid('hideCol',infoName );

Any better solutions welcomed.

Brandon
Be aware that `.trim()` is not supported in all browsers. You should probably use jQuery's `$.trim()` method. `var infoName = $.trim( $('.ui-jqgrid-htable th:eq(4)').text() );`
patrick dw
you are right... that threw an error in IE.. amended.
Brandon
A: 

You can just use

var cm = myGrid.getGridParam("colModel");

to get the current colModel. Then cm[4].name is the name of the column. So

var colPos = 4;
var myGrid = $('#tblGridName');
myGrid.jqGrid('hideCol', myGrid.getGridParam("colModel")[colPos].name);

do what you need.

Oleg