Range filtering (numbers)

Filter the data between two numbers (inclusive)

Filter a specific numeric column on the value being between two given numbers. Note that you will likely need to change the id's on the inputs and the column in which the numeric value is given.

Plug-in code

jQuery.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
        var iColumn = 3;
        var iMin = document.getElementById('min').value * 1;
        var iMax = document.getElementById('max').value * 1;

        var iVersion = aData[iColumn] == "-" ? 0 : aData[iColumn]*1;
        if ( iMin === "" && iMax === "" )
        {
            return true;
        }
        else if ( iMin === "" && iVersion < iMax )
        {
            return true;
        }
        else if ( iMin < iVersion && "" === iMax )
        {
            return true;
        }
        else if ( iMin < iVersion && iVersion < iMax )
        {
            return true;
        }
        return false;
    }
);

CDN

This plug-in is available on the DataTables CDN:

JS

Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!

Example

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

      // Add event listeners to the two range filtering inputs
      $('#min').keyup( function() { table.draw(); } );
      $('#max').keyup( function() { table.draw(); } );
  } );