Adding Buttons via For Loop
Adding Buttons via For Loop
I've successfully used table.button().add() function to add three buttons, each with separate action and active toggle, as demonstrated here: ButtonAdd.
But when I attempt to add the same three buttons with a for loop, the action for all three buttons is same as button three, as demonstrated here: ButtonAddLoop.
Any idea what I'm doing wrong? Is there a better way to add lots of buttons with a for loop, perhaps via Constructor $.fn.dataTable.Buttons() or buttons().containers() function?
Thanks, as always, in advance.
Charles
This question has an accepted answers - jump to answer
Answers
I don't know all the details but it has something to do with each function referencing the same variable object. I moved your test case here to show that each function is actually different by getting the
button().text()
.http://live.datatables.net/ceraxatu/1/edit
Kevin
Thank you Kevin! You are a jewel. Your demo helped me figure out an approach that works nicely now.
Yes, I too don't fully understand, but I think you are correct.
It may too be related to a similar issue discussed in the following thread: onClick event in a For loop
In any case, thank you again!
Charles