Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82029

Adding a search box for every column causes to sort the column too....

$
0
0

Hi All,
I have been working with DataTables for a while now. I am trying to implement the "Search Box" feature for every column in the generated table. The issue I am facing is that even If I am clicking on the Input text box to place the cursor and make a column specific search, the column sorts it self. I understand the fact that I am cloning the "thead" and then making the search, but is there anyway to be able to prevent the sorting and just perform search. Here is the code. Any help would be greatly appreciated. Thanks!

 var table = $("#example2").DataTable();
        $('#example2 thead tr').clone(true).appendTo('#example2 thead');
        $('#example2 thead tr:eq(1) th').each(function(i) {
            var title = $(this).text();
            $(this).html('<input size="10" type="text" placeholder="Search ' + title + '" />');
            $('input', this).on('keyup change', function() {
                //console.log("Event in the INPUT");
                e.preventDefault();
                if (table.column(i).search() !== this.value) {
                    table
                        .column(i)
                        .search(this.value)
                        .draw();
                }
                $(this).attr("id", "someId");
            });
        });

Viewing all articles
Browse latest Browse all 82029

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>