Initcomplete not working well on multiple tables
Initcomplete not working well on multiple tables
giora
Posts: 4Questions: 2Answers: 1
as i am saying on the title when i am using init of datatables more then once the each table has been initialized the select of all the tables gets the data from last table
initComplete : function () {
this.api().column(1).every(function(){
var column = this;
var select = $('<select class="form-control input-sm"><option value="">All</option></select>')
.appendTo( $('.filter_data2').empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
});
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I suspect your problem is with your '.filter_data2' selector. As is, it will find all instances containing that class name. Since your select box is inside the table try this: $('filter_data2', this).empty() ... to limit the scope of your selector.
no its not worked its not work generaly the sorting
fixed wih $(table).parents('.dataTables_wrapper').find('.filter_data2')
the table variable is the
var table = this pre initialize
Yes, that looks like a good change. Thanks for posting back.
Allan