0

In the jQuery DataTables example of Custom filtering - range search if I enter a value, example "41" in the input field Maximun age, the table gets updated just after I click the first number (the "4"), and this way all the rows disappear until I the also digit the second number (the "1"). Is there a way to wait to update the table untill the second number is digited (let's assume that we don't want numbers less than 10)? Is it possible even to update just if I click enter?

1
  • check here Commented Jun 10, 2015 at 20:24

1 Answer 1

1

try this:

$(document).ready(function() {
    var table = $('#example').DataTable();

    // Event listener to the two range filtering inputs to redraw on input
    $('#min, #max').keypress( function(event) {

        var max = parseInt( $('#max').val(), 10 );
        if(event.which!==13 || max<10)
            return;
        table.draw();
    } );
} );

I replace keyup for keypress and capture the key 13 (enter). When the user press enter or max value is less than 10, dont draw the table.

see http://jsfiddle.net/andresrondan/gygskjgx/

hope this helps

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

2 Comments

Thanks it helps. Just one more case: if my field value are dates should I use this approach (I think it works: >999 if I want to enter YYYY), or is it a better way?
Thanks! I dont know the context of your application but filter >999 seems a good solution. ;)

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.