Problem with multi table initialization
Problem with multi table initialization

My HTML page has multiple tables. I wish to show all the child rows for each table on page load.
Here's my JavaScript:
Sys.Application.add_load(function () {
var data = $('table.datatables').DataTable({
fixedHeader: {
footer: true,
header: true,
headerOffset: 60
},
lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
retrieve: true
});
data.rows().every(function (rowIdx, tableLoop, rowLoop) {
//? this context always refers to a row in the first table (0), even when tableLoop equals 1
if (!this.child.isShown()) {
var tr = $(this.node());
var note = tr.data().childNote;
if (note != null && note.length > 0) {
this.child(note).show();
this.child().addClass(tr.attr('class'));
}
}
});
});
My HTML page has multiple tables and the data-child-note attribute is set for some rows.
The first table displays correctly. However, subsequent tables shows child notes from the first table.
Examination of the raw HTML shows the notes in the correct data-child-note attributes.
Therefore, when debugging this script, this is what I discovered.
The every function does iterate over every row in every table and tableLoop and rowLoop does increment as expected.
However, the this context of the called function always refers to a row in table(0), even when tableLoop is greater than 0.
As a result, the child rows for subsequent tables show the child rows from the first table and not from the current table.
This seems like a defect.
As a workaround, can someone suggest how can I use the tableLoop and rowLoop values to obtain the correct row?
Thank you,
This question has an accepted answers - jump to answer
Answers
There is a defect in the datatables script, starting at line 9422.
// Add the 'every()' method for rows, columns and cells in a compact form
Original script:
Notice the function call (line 18 of sample) does not make use of the table counter parameter, hence the default to table 0.
This revised script fixes the problem:
Hopefully the powers that be will pick this up and incorporate into the downloadable version.
Hi @DonSolo ,
You need to use the
tables()
to get to the specific table for those API calls - something like this.Cheers,
Colin
Sorry, I forgot the link. Here it is: http://live.datatables.net/kewiyafa/1/edit