visible: function
visible: function
Andreas S.
Posts: 208Questions: 74Answers: 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
This discussion has been closed.
Answers
If
data.recordRights
is a different column then you probably wantrow.recordRights
instead.I think you will end up with either
true
orfalse
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
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:
and if rights set to 0, they should not see the column 8:
My Problem is the function did not work and I haven't any idea what is my failure.
Andreas
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
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 usevisible: data.recordRights === 1 ? true : false
.Allan