Add button conditionally
Add button conditionally

I can't find in the documentation or existing example on how to add button to a specific button layout group. In the example below, I want to add the Notify button in the topEnd only when the user has permission to do so. I am able to add the button after the datatable is initialized thinking it will take into consideration the index but it's adding the button to the first group.
Can someone help. Thanks.
var dt = new DataTable('#example', {
paging: false,
ordering: false,
info: false,
layout: {
topStart: {
buttons: ['csv', 'excel']
},
topEnd: {
buttons: [{
text: 'Invite',
action: function (e, dt, node, config) {
$('#InviteModal').modal('toggle')
}
}
/* ,{
text: 'Notify',
action: function (e, dt, node, config) {
$('#notifyModal').modal('toggle')
}
} */
]
}
}
}
);
dt.button().add(4, {
action: function (e, dt, button, config) {
$('#notififyModal').modal('toggle')
},
text: 'Notify'
});
Answers
I'd use a variable before the initialisation:
Then for the assignment:
Allan
Thanks, I'll give it a try