Adding buttons after load.
Adding buttons after load.
Hey,
Should I be able to do something like this?:
let table = $('#datatables-table');
table.button().add( 0, {
action: function ( e, dt, button, config ) {
dt.ajax.reload();
},
text: 'Reload table'
} );
I'm just trying to add these standard buttons after the initialise:
buttons: [{extend:'remove', editor: editor},{extend:'create', editor: editor},{extend:'edit', editor: editor}],
Mick
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Mick,
In the above
table
is a jQuery instance, not a DataTables API instance. You would need to use:to get a DataTables API instance (which has the
button()
method available on it).With the above I think it should probably be giving a Javascript error about the
button
function not existing.Regards,
Allan
Yes, that works now. I thought I did that initially and got an error because the table was already initialised. Thanks.
What about adding the standard buttons at this point?
FYI I am creating a Vue.js component for my Datatables and I am trying to pass
As a variable but can't find a way to do it without it sticking " around it (when it's a string) and I can't pass it as JSON, because the editor needs to be without quotes.
This is why I am adding the buttons after the load, I will use this component whenever I use a Datatable and the buttons I require will vary.
Mick
Hey Allan,
Did you see this?
"What about adding the standard buttons at this point?"
Thanks,
Mick
Sorry I missed that part.
You can use the
button().add()
method to add the Editor buttons as well:Any button that can be added using the
buttons.buttons
array can also be added using the API at any time after the initialisation.Allan
Brilliant!
Thanks