Using column(x).search(v).draw() doesn't work unless I Destroy() first

Using column(x).search(v).draw() doesn't work unless I Destroy() first

timcadieuxtimcadieux Posts: 76Questions: 22Answers: 0

As mentioned above, I am attempting to use some Buttons to filter to content. Using a button click, I attempt to filter based on a specific column..

The below works IF I use table.destroy...but doing that causes the table to lose its layout?

 initComplete: function () {
            //Use Buttons to change Region
            $('#table-filters').on('click', function (event) {

                var v = $(event.target).val();
                var i = event.target.id;

                var table = new $.fn.dataTable.Api("#datatable");
                table.destroy();
                table.column(19).search(v).draw();

            });

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    Destroying the table doesn't seem like the right solution. I can see that it would loose formatting. Maybe you can put together is simple test case replicating your code so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • timcadieuxtimcadieux Posts: 76Questions: 22Answers: 0

    Thx. I created an example at the link below but mu on click isn't being captured there at all.

    http://live.datatables.net/rakuneni/1/

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @timcadieux ,

    Try this, it should do the trick:

    initComplete: function() {
        //Use Buttons to change Region
        var api = this.api();
        $('#table-filters').on('click', function(event) {
    
          var v = $(event.target).val();
          var i = event.target.id;
    
          api.column(19).search(v).draw();
    
        });
    

    If that doesn't work, 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.

    Cheers,

    Colin

  • timcadieuxtimcadieux Posts: 76Questions: 22Answers: 0

    That did the job, thank you.

This discussion has been closed.