I have a datatable
with a column defaultContent
, where I have buttons to edit, delete and give privileges but I want to hide it if the profile type is user, that is, only the administrator can see that column
usser.js ...
$(document).ready(function(){
//...
var table = $('#dt_usser').DataTable({
"ajax": "php/usser_cargar.php",
"columns":[
{ "data": "num_emp", "visible": false},
{ "data": "nom"},
{ "data": "nom_usu"},
{ "data": "tipo"},
{ "data": "status", "sClass": "dt-body-center"},
{"defaultContent": '<div class="text-center"> <button title="Editar perfil." type="button" class="editar btn btn-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button> <button title="Eliminar usuario" type="button" class="eliminar btn btn-danger"><i class="fa fa-trash-o" aria-hidden="true"></i></button> <button title="." type="button" class="privilegios btn btn-default"><i class="fa fa-key" aria-hidden="true"></i></button> </div>', "width": "15%" }
],"language": datables_espanol
//...
}
How to hide column defaultContent
with handling session
?
I wanted to perform a function within the same js but it stops showing all the data in the table.
function direc(){
if (<?$_SESSION['usrSis_tipo'];?> === 'U'){
table.columns([5]).visible(false);
}
};
In usser.php
is the structure of the table that is filled with the code placed in usser.js
, and usser_cargar.php
the query is made to the database and the data is sent in JSON