Changing dom based on table ID
Changing dom based on table ID
Hello guys,
I am trying to change table layout based on its ID. I've already did it with cols order :
var tables = $('table').DataTable();
$('table').each(function(){
var id = $(this).attr("id");
if (id=="example2"){
table
$('#'+id).DataTable().order( [[ 1, 'desc' ]] )
.draw( false );
}
});
Now I am trying to do something like this but this option tells me it can't reinitialize the table:
var tables = $('table').DataTable();
$('table').each(function(){
var id = $(this).attr("id");
if (id=="example2"){
table
$('#'+id).DataTable({
dom: 'Btrp',
buttons: [
{
extend: 'excelHtml5',
footer:true,
text: 'Excel',
customize: function( xlsx ) {
setSheetName(xlsx, 'Calls');
addSheet(xlsx, '#example2', 'My Sheet2', 'Summary2', '2');
addSheet(xlsx, '#example3', 'My Sheet3', 'Summary3', '3');
addSheet(xlsx, '#example4', 'My Sheet4', 'Summary4', '4');
addSheet(xlsx, '#example5', 'My Sheet5', 'Summary5', '5');
addSheet(xlsx, '#example6', 'My Sheet6', 'Summary6', '6');
}
}
]
}) } });
I know how it works with individual initializing but I have to use tables() API.
Is there any kind of loop that's going through the tables and allows me to change stuff like this. If anyone have idea I would really appreciate.
Here my full code : http://live.datatables.net/gidebiko/9/edit
This question has an accepted answers - jump to answer
Answers
I'm a little confused by what you are trying to do.
Line 1 above will initialise a DataTable on every matching element (in this case all
table
elements on the page). Then you go on to loop over each table and configure a DataTable for a specific id. By that is already a DataTable - hence the error message directing you here: https://datatables.net/manual/tech-notes/3 .Perhaps you should change it so that there is an
else
statement in the loop. If it isn't the table you want to provide specific options for, then initialise it as a DataTable without options. Then remove line 1.Allan
Thank you Allan! Best regards!