开发者

How do I hide a jqGrid column of variable name?

开发者 https://www.devze.com 2023-01-10 06:33 出处:网络
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)

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('hi开发者_JAVA技巧deCol',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.

0

精彩评论

暂无评论...
验证码 换一张
取 消