2

I am using Datatables and require both horizontal scrolling and filtering. It appears that they try to write to the same area and I can't get both to work. If I enable filtering, it will filter once then then filter disappears.

Any clues? It is within an intranet so I can't post code.

6
  • 3
    -1 for no code example, no research effort shown. Check DataTables forums and existing DataTables GitHub issues. If your case is not there, create a test case and publish it in the DataTables forums at datatables.net/forums/discussion/12899/… Commented May 28, 2014 at 16:13
  • you can put your test case (run-able example of your problem) on a public site like jsFiddle or jsBin or CodePen or live.DataTables.net or anywhere else.. supportive? Commented May 28, 2014 at 18:18
  • Fair enough. I rescind my previous comment and will look to generalize the issue. Commented May 28, 2014 at 18:22
  • 1
    Fair enough. My -1 vote was because you did not keep basic Stack Overflow rules (e.g. stackoverflow.com/help/mcve). The link to DataTables forums and test case is a MUST if you want Allan Jardine (the author) to help you. I needed his help myself just 2 days ago and I also had to provide a test case. If you improve your question I'll remove my downvote Commented May 28, 2014 at 18:35
  • 1
    I have found the answer by creating a separate area for filtering that is outside of the datatable. In the future, I will be better about the following the rules and providing test cases. Here is a link to what I am implementing: datatables.net/examples/api/regex.html Note that it resides outside of the datatable Commented May 29, 2014 at 15:41

1 Answer 1

2

I had the same problem. After many attempts I found two solutions to solve this. Here are the options:

1) If you want to put the column filters after the first header (title of column and ordering), the following code snippet worked:

table.columns().eq(0).each( function ( colIdx ) {
    $( 'input', otable.column( colIdx ).header() ).on( 'keyup change', function() {
        table
            .column( colIdx )
            .search( this.value )
            .draw();
    });
});

2) Else, type the following code snippet after create a table object:

table.columns().eq(0).each( function ( colIdx ) {
     $( 'input', 'th:nth-child('+(colIdx+1)+')' ).on( 'keyup change', function() {
          table
              .column( colIdx )
              .search( this.value )
              .draw();
     });
});

Regards. Joao Lucas.

Sign up to request clarification or add additional context in comments.

1 Comment

Where do you put the first code? directly on the DataTable script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.