How do I hide a jqGrid column of variable name?

11,076

Solution 1

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.

Solution 2

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.

Share:
11,076
bcm
Author by

bcm

Updated on June 04, 2022

Comments

  • bcm
    bcm over 1 year

    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 );