javascript 如何隐藏变量名的 jqGrid 列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3384088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I hide a jqGrid column of variable name?
提问by bcm
I have a jqGrid column which name may change (is a variable), how do I get the name and hide it?
我有一个 jqGrid 列,其名称可能会更改(是一个变量),如何获取名称并将其隐藏?
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 );
回答by Oleg
You can just use
你可以使用
var cm = myGrid.getGridParam("colModel");
to get the current colModel. Then cm[4].nameis the name of the column. So
获取当前colModel. 然后cm[4].name是列的名称。所以
var colPos = 4;
var myGrid = $('#tblGridName');
myGrid.jqGrid('hideCol', myGrid.getGridParam("colModel")[colPos].name);
do what you need.
做你需要的。
回答by bcm
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.
欢迎任何更好的解决方案。

