简体   繁体   English

如何使用用户选项隐藏 jQuery jTable 中的特定列?

[英]How to hide a particular column in jQuery jTable with the user option?

I am using jQuery jtable to fetch data from my server.我正在使用 jQuery jtable 从我的服务器获取数据。 In my jtable I need to hide certain columns with the user option, for this I have written a function inside my fields as shown.在我的 jtable 中,我需要使用用户选项隐藏某些列,为此我在我的字段中编写了一个函数,如图所示。 In this particular table I want to hide the Description column for this I am getting the value such as 'Device Fault' from the user.在这个特定的表中,我想隐藏描述列,我从用户那里得到了诸如“设备故障”之类的值。 So, if the user select device fault I want to hide only that particular column in the table.因此,如果用户选择设备故障,我只想隐藏表中的特定列。

        fields: {
        Date: {
            title: 'Date',
        },
        Event_name: {
            title: 'Event Name',
        },
        Event_Description: {
            title: 'Event Description',

        },
        Tag: {
            title: 'Tag',
        },
        Description: {
            title: 'Description',
            visibility: function(data){
              if(selectedEventName == 'Device Faults'){
                return = hidden;
              }
              else{
                return = fixed;
              }
            },
        },
        Serial_number: {
            title: 'Serial Number',
        },
        IP_address: {
            title: 'IP Address',
        },
    },

How can I achieve this, can someone help me with this.我怎样才能做到这一点,有人可以帮我解决这个问题。

Thanks谢谢

First thing to say, is that jTable may have built in functionality that will meet the user requirement.首先要说的是,jTable 可能内置了满足用户需求的功能。 Right click on the column headings and a pop up appears, where columns can be checked/unchecked to display or hide the column respectively.右键单击列标题,会出现一个弹出窗口,可以选中/取消选中列以分别显示或隐藏该列。

Secondly, the field option visibility must be a static value not a function.其次,字段选项visibility必须是静态值而不是函数。

Once the table has been initialised, you can use the jtable('changeColumnVisibility') function to hide or display a column.表初始化后,您可以使用jtable('changeColumnVisibility')函数隐藏或显示列。

eg.例如。

$('#mytable').jtable('changeColumnVisibility','Description','hidden');

You can use visibility: 'hidden'.您可以使用可见性:'隐藏'。 For Example.......例如.......

 fields: {
        HiddenInfo: {
            title: 'HiddenInfo',
            width: '10%',
            visibility: 'hidden'
        },

More details, visit.... http://jtable.org/Demo/ColumnHideShow更多详情,请访问.... http://jtable.org/Demo/ColumnHideShow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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