Iterating through buttons
Iterating through buttons
I have n number of tables (with unique ids) on the table initialized with DataTables(). Each table has a set of the same buttons to be able to filter that particular table with the certain date ranges. No matter how i get the buttons i keep getting a list of all tables instances and then inside there i need to somehow figure out which one is mine and then call buttons() to get buttons from that instance.
here's some inconsistency. this gives me instance dt.table().node() but somehow dt.table().buttons() gives me all 4 tables instances with instance buttons somewhere in there. I would have to do something similar to this
dt.buttons('.quartertoggle').each(function(value, index){
// no clue why it needs to be this way? it seems to dump all the table instances at once
value.inst.s.buttons.forEach( b => {
if(b.node.hasClass('btn-primary'))
quarters.push(b.node.text());
});
});
Am I missing something here? Why inside my dt variable all of a sudden i get all the instances if i'm looking for buttons? Specifically how do i iterate though the button of a particular instance?
This question has an accepted answers - jump to answer
Answers
There is a difference between
dt.table().buttons()
anddt.buttons()
. Presumably you are initializing multiple tables at once, like this example, and assigning the APIs to the variabledt
. Usingdt.table()
will return the first Datatable API.dt.table(1)
will return the second Datatable. See thetable()
docs for more info.However
dt
contains the API for all the Datatables.dt.buttons()
will return all the buttons for all the tables. See this example:http://live.datatables.net/nupubewu/1/edit
The example shows one way to iterate the buttons for just one of the tables.
Kevin