Adding bootstrap data-toogle & data-target into data-table button
Adding bootstrap data-toogle & data-target into data-table button
Muhammad Izzat
Posts: 22Questions: 10Answers: 0
Hi everyone, I have an issue similiar to this, but I'm having trouble understanding the answer
Originally I have a button with bootstrap data-toggle in it
<button
data-toggle="modal" data-target="#create_new_workorder"
type="button" class="btn btn-sm btn-warning btn-outline"><span
class="hidden-md hidden-sm hidden-xs">Create Workorder</span> <i
class="fa fa-fw fa-plus"></i>
</button>
but now I'm using data-table button which looks something like this
buttons: [
{
text: 'Create Workoreder',
action: function () {
create_workorder_window();
},
className: 'btn btn-warning btn-outline'
},
{ extend: 'colvis', text: 'Show', className: 'btn btn-warning btn-outline'}
],
how can I add the data-toggle="modal"
and the data-target="#create_new_workorder"
?
Any help is much appreciated
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You could use jquery .attr(...) function on the button nodes to add your data attributes. Something like:
Buttons API - node() fn: https://datatables.net/reference/api/buttons().nodes()
You could use a class name on the button and supply the selector to the buttons(...) call to add the attributes to specific buttons if required.
like:
then:
Hi @rduncecb, thank you for your answer and apology for the late reply, I now have better understanding on how the button API works thanks to you but there is a slight problem, I can change the css and everything but whenever I try to declare the button attribute, my data-table stop working, this is my code :
Using class is only one way you can open a bootstrap modal. You can also open it with code.
https://www.w3schools.com/Bootstrap/tryit.asp?filename=trybs_ref_js_modal_js&stacked=h
Found a solution, just declare this above my data-table script