Use php variable in datatables in a if function to prevent the option to show colomn
Use php variable in datatables in a if function to prevent the option to show colomn
martin1223345
Posts: 84Questions: 23Answers: 0
In php I have a variable called $status. When the user has the status 4 or higher it should be able to show the colomns email and pass (not defined at this moment). Can i use this variable in a if statement in my datatables script?
Example (i know there are syntacs mistakes in my if statement but i dont know if and how to emply in this function):
dom: 'Bfrtip',
buttons: [
{
extend: 'collection',
text: 'Table control',
buttons: [
{
text: 'Show Type',
if ( $status >= 4){
action: function ( e, dt, node, config ) {
dt.column( -9 ).visible( ! dt.column( -9 ).visible() );
} }
},
{
text: 'Show Plane',
action: function ( e, dt, node, config ) {
dt.column( -6 ).visible( ! dt.column( -6 ).visible() );
}
}
]
}
]
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This SO thread should help - it would be best to search on there as this is a standard JS/PHP question,
Colin
Thanks for you reaction. I have tried it like this.
This code shows my variable correctly in the console log so that goes well i guess.
But now i want to use it in a input form, I can't seem to get this to work. What am i doing wrong? Tried is on more ways
The problem is not with the variable but with the syntax of your
input
tag. All of the parameters need to have quotes around the values.In one case you have:
If you want the value to be the string
php_va
then it needs to look like this:value="php_va"
.If you want the value of the variable then it needs to look like this:
value="' + php_va + '"
.You can use console.log in the render function to output the string you are building to verify its correct. You can then copy it into your HTML just to see if its working.
See this tutorial for more info on string concatenation with variables.
Kevin
Thank you !