Santha Kumar
Santha Kumar

Reputation: 83

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

I am using jQuery jtable to fetch data from my server. 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. 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

Upvotes: 0

Views: 1643

Answers (2)

Rejwanul Reja
Rejwanul Reja

Reputation: 1491

You can use visibility: 'hidden'. For Example.......

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

More details, visit.... http://jtable.org/Demo/ColumnHideShow

Upvotes: 1

misterP
misterP

Reputation: 185

First thing to say, is that jTable may have built in functionality that will meet the user requirement. 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 visibilitymust be a static value not a function.

Once the table has been initialised, you can use the jtable('changeColumnVisibility') function to hide or display a column.

eg.

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

Upvotes: 2

Related Questions