How to re-fill dataTable on text change

How to re-fill dataTable on text change

Fandry NoutahFandry Noutah Posts: 1Questions: 1Answers: 0
edited May 2020 in Free community support

Hello everyone, I have my dataTable filled with ajax from another PHP page (json encoded).
And I want to add a select box near the entries filter to filter my dataTable.
So how can I re-fill the dataTable when my own selectBox change?

I tried this but it's not working

            $(document).ready(function(){
                var dataTable = $('#student_table').DataTable({
                    "processing": true,
                    "serverSide": true,
                    "order": [],
                    "ajax": {
                        url: 'student_action.php',
                        type: 'POST',
                        data: {action: 'fetch'}
                    },
                    "columnDefs": [{
                        "targets": [0,1,2,3,4,5],
                        "orderable": false
                    }]
                });

                $('#promo_filter').change(function(){
                    $('#student_table').DataTable({
                        "processing": true,
                        "serverSide": true,
                        "order": [],
                        "ajax": {
                            url: 'student_action.php',
                            type: 'POST',
                            data: {id_promotion:$(this).val()}
                        },
                        "columnDefs": [{
                            "targets": [0,1,2,3,4,5],
                            "orderable": false
                        }]
                    });

                });
            });

thanks

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You would need to destroy the original table first, either with destroy() or destroy.

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Colin

This discussion has been closed.