Initcomplete not working well on multiple tables

Initcomplete not working well on multiple tables

gioragiora 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

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    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.

  • gioragiora Posts: 4Questions: 2Answers: 1

    no its not worked its not work generaly the sorting

  • gioragiora Posts: 4Questions: 2Answers: 1
    Answer ✓

    fixed wih $(table).parents('.dataTables_wrapper').find('.filter_data2')
    the table variable is the
    var table = this pre initialize

  • allanallan Posts: 63,844Questions: 1Answers: 10,518 Site admin

    Yes, that looks like a good change. Thanks for posting back.

    Allan

This discussion has been closed.