GridManager 隐藏列

GridManager 表格管理组件, 对列的隐藏与显示的操作有两种方式。

初始化时指定列为隐藏或显示状态。方式如下:

<table></table>
var table = document.querySelector('table');
table.GM({
    gridManagerName: 'test',
    ajax_url: 'http://www.lovejavascript.com/learnLinkManager/getLearnLinkList',
    columnData: [{
        key: 'name',
        // 指定不显示该列
        isShow: false,
        text: 'username'
    },{
        key: 'type',
        // 指定显示该列
        isShow: true,
        text: 'type'
    },{
        key: 'info',
        // 不指定该列的显示状态, 默认为true
        text: 'info'
    }]
});

渲染完成后,对列进行隐藏或显示操作。在已经执行过init的前提下,可通过如下方式对列进行操作:

// 对第一列进行显示
var table = document.querySelector('table');
var th_name = table.querySelector('th[th-name="name"]');
table.GM('showTh', th_name);
// 对第二列进行隐藏
var table = document.querySelector('table');
var th_type = table.querySelector('th[th-name="type"]');
table.GM('hideTh', th_type);
// 批量操作 -> 隐藏第二和第三列
var table = document.querySelector('table');
var thList = table.querySelectorAll('th');
document.querySelector('table').GM('hideTh', [thList[1], thList[2]]); 
// 批量操作 -> 显示全部列
var table = document.querySelector('table');
var thList = table.querySelectorAll('th');
document.querySelector('table').GM('showTh', thList); 
    原文作者:拭目以待
    原文地址: https://segmentfault.com/a/1190000014800147
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞