简体   繁体   中英

How do I hide a jqGrid column of variable name?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM