Show or hide collectors button with if statement
Show or hide collectors button with if statement
martin1223345
Posts: 84Questions: 23Answers: 0
I am trying to inplent the if statement in the buttons function. I cant seem to find the right syntaxt, it keeps saying error.. I need the button to show or hide to be not there when the condition is not matched.
I tried to do it like this, and on a lot of other ways but nothing seems to be correct. Doing it this way was the only accepted syntax option but this wont remove the button from sight..
dom: 'Bfrtip',
buttons: [
{
extend: 'collection',
text: 'Table control',
buttons: [
{
text: 'Show Type',
action: function ( e, dt, node, config ) {
if (php_va == "Hardbeat")
dt.column( -11 ).visible( ! dt.column( -11 ).visible() );
}
},
{
text: 'Show Plane',
action: function ( e, dt, node, config ) {
dt.column( -8 ).visible( ! dt.column( -8 ).visible() );
}
},
{
text: 'Show Invite',
action: function ( e, dt, node, config ) {
dt.column( -2 ).visible( ! dt.column( -2 ).visible() );
}
},
{
text: 'Show Send location',
action: function ( e, dt, node, config ) {
dt.column( -1 ).visible( ! dt.column( -1 ).visible() );
}
}
]
}
]
});
This discussion has been closed.
Answers
That if statement will only execute when you click the button. See this thread for ideas on showing/hiding buttons based on condition.
Kevin
Thanks for reacting. I tried that example but i get this error? Uncaught SyntaxError:
The problem is you copied that code inside your Datatables initialization parameters. That wont work. That code needs to be outside of the Datatables initialization function.
Look at the last post in the thread. Use the
buttons.buttons.className
to assign a classname to the button(s) you want to show/hide based on the condition. Before your Datatables initialization code set that classname like shown in the thread to hide the button.Kevin