本文介绍了jqgrid-在setcolumns之后将所有列重置为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用setColumns函数在客户端动态显示/隐藏列.

i have used setColumns function to show/hide columns dynamically on client-side.

现在我想将所有列重置为默认视图.如何做到这一点.

now i want to reset all the columns to default view.. how to do that.

以下是我使用的代码

$("#list").navButtonAdd('#pager', {
  caption: "View",
  title: "Click here to select Columns to view",
  onClickButton: function() {
    var params = {width:500,modal:true,drag:true};
    jQuery("#list").setColumns(params);
  },
  position: "last"
});

我需要复位之类的东西.

i need something like reset.

jqgrid的刷新按钮只是刷新具有选定列的表,而不重置它们.

refresh button for the jqgrid is just refreshing the table with selected columns but not reseting them.

谢谢,桑迪普

推荐答案

我可以将原始colModel参数保存在变量中,并使用hidden属性的初始值显示或隐藏列:

I can save the original colModel parameter in a variable and use the initial values of hidden properties to show or to hide the columns:

var grid = $("#list"),
    cm = [
        { name:'id', hidden:true, ... }, // initially hidden column
        { name:'name', ...},             // initially non-hidden column
        ...
    ];
grid.jqGrid({
    colModel:cm,
    // ... other jqGrid parameters
});
grid.jqGrid('navButtonAdd','#pager', {
    caption: "Reset Columns",
    title: "Click here to select Columns to view",
    onClickButton: function() {
        var i=0, cmi, l=cm.length;
        for (;i<l;i++) {
            cmi=cm[i];
            if (typeof cmi.hidden === 'undefined' || cmi.hidden === false) {
                grid.jqGrid('showCol',cmi.name);
            } else {
                grid.jqGrid('hideCol',cmi.name);
            }
        }
    },
    position: "Reset"
});

此处中查看演示.

这篇关于jqgrid-在setcolumns之后将所有列重置为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 14:41