How to add "data-*" html attribute to some dt button
How to add "data-*" html attribute to some dt button
orney21d@gmail.com
Posts: 23Questions: 7Answers: 3
I would like to add some html attribute to "a" generated by datatable buttons without doing it by JQuery but datatable api. Button have "className", "Text" properties in extends but i don't see option to add custom attributes... How can i do that. Thanks .
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
There is no option to add in custom attributes. You have to do it using jQuery and the API.
Example
Thanks
Tom
Hi Tom,
Thanks for the answer. i understand you but i'm unable to get reference to some button.
I have definitión and all is fine, buttons is working nice but i wana to get reference to some of them to modify as you toldme.
i have inside DataTable options the buttons def...:
After instanciate my datatable:
i wana to get the copy button as follow to modify it:
But i see that
datatable.button( 'copyBtn:name' ).length is equal to "0"
What i'm doing wrong??.
Best regards.
For some reason i need to do
after datatable definition, and then i can do :
datatable.button(0)
getting the button reference... i Dont understand yet why should i do that...My guess is that you are Ajax loading the data for your table - although without the full code or a link to a test case it is impossible to say. The reason for that is that Buttons will initialise when the table is fully ready. If the table load is async, then so it Buttons.
You could use
initComplete
and modify the buttons in there.Allan
Hi @allan, thanks for the response... I should to say you that there isn't ajax loading, maybe in the future jeje, but for testing purpose i just want first customize some things:
The load :
Setting datasource and defining buttons:
After that i want to add some attribute to first button for example:
$("a", datatable.buttons(0).container(0)).first().attr('data-toggle', 'tooltip')
In the before line i see for example that if i haven't the next sentence:
then :
datatable.buttons(0) ==0
So, when i define buttons again in following sentence:
i can access buttons, but when i add attribute as set before in the first button (copy button), i want to override div buttons section, this section have a classes "dt-buttons, .btn-group", so i do:
$(".dt-buttons, .btn-group").replaceWith(datatable.buttons(0, null).containers());
but after all load, i sow that the attributes i added to "anchors" buttons isn't there, so,
It has not been made any modification...
Any suggestion??.
Thanks very much...
Are you using the
dom
property to insert the buttons onto the page? Again, without a test case it is impossible to say. This is why the forum rules request that a test case give given so we don't need to guess and we don't have this back-and-forth.I'm afraid I don't understand - could you clarify this point.
Allan
Hi everybody, @allan sorry for the little explanation... My english is not so good so, sorry for that too... I have resolve my issue, i'll explain how... The fact is that when I tried to change the html buttons of DataTable, it seems that even the datatable had not loaded completely it's components like buttons and more... So what i did is to attach to "init.dt" event, and inside this event modify what i wanted. i show you how:
I hope I explained better...
Thanks all very much for the feedback.
if there is anything i'll be glad in collaborate
How to mark this post as answered??
I've done so now. Thanks for letting me know.
Allan