visible: function

visible: function

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

I need some columns to invisible if the rights are not given. I tried to do this, but that did not work.

{ targets: 8, visible: function(data, type, row){
  return (data.recordRights == '1')? true : false;
  }
},

I have no ideas at this time where is my fault. Have someone a idea?

Andreas

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    If data.recordRights is a different column then you probably want row.recordRights instead.

    I think you will end up with either true or false displayed in your column. Assuming you want to display the data if true and display a blank if false you may want to change the return to something like this:
    return (row.recordRights == '1')? data : '';

    Kevin

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4
    edited January 2017

    The data.recordRights is not in a column. It is a user right that are set to 1 if the User have the rights to see the column.

    I want the output if the rights is set to 1, they should see column 8:

    { targets: 8, visible: true  }
    

    and if rights set to 0, they should not see the column 8:

    { targets: 8, visible: false }
    

    My Problem is the function did not work and I haven't any idea what is my failure.

    Andreas

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769
    edited January 2017

    I see, misunderstood what you were doing :-)

    I think you will need to use the initComplete() to process the received data to hide the columns.

    EDIT: In case of processing delays a better option may be to get the permissions before initializing the table and assigning the desired configuration to a columnDefs variable. Then assign that variable to the columnDefs.

    Kevin

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    columns.visible can't be given as a function. As the documentation for it notes, it should be a boolean value.

    If you have access to the data variable at that point (i.e. you are Ajax loading the data yourself, or it is Javascript sourced) you could just use visible: data.recordRights === 1 ? true : false.

    Allan

This discussion has been closed.