Using DataTables in Wordpress, want to hide cols depending on user role
Using DataTables in Wordpress, want to hide cols depending on user role
eliwbbr
Posts: 1Questions: 1Answers: 0
I've initialised DataTables on a WordPress page that is displaying information on moulding profiles. Depending on whether or not the user is a) logged in and b) the correct user type (either an operator (which is a custom user role) or an Admin), then the table will display a few extra columns of information. My script is below, but its displaying all columns regardless of login.
$(document).ready(function(){
$('#profiles_table').DataTable({
columnDefs : [
{ targets: [2, 11, 12, 13 ], visible: document.getElementById('role').value == '[operator,ROLE_ADMIN]' }
]
});
});
Any help or suggestions would be great! Much appreciated!!!
This discussion has been closed.
Answers
Hi @eliwbbr ,
Yeah, it doesn't like when you do too complex a thing in those initialisation lines. See the example here, it's best to separate the test from the initialisation.
Hope that helps,
Ceers,
Colin