3

I'm working with datatables and I need to use search() as follows:

let table = $('#datatable-table').DataTable();
$('#boton-filtrar').click(function (e) {
e.preventDefault();
table
  .column(8)
  .search('> 20') //Here is the cuestion!
  .draw();
  });

That is, create a search filter in column 8 that returns all numbers greater than 20.

Column number 8 contains numerical values.

20 is by way of example, since the value will be given by another input that is already prepared.

I have searched but I have not found anything.

Some help? Thank you.

Jose
  • 158
  • 3
  • 14
  • the value you've assigned in `search` might be treated as `string` input by Datatables and that is why not be working, you should use either regular expression or other option mentioned in their API's – Rajender Verma Oct 28 '18 at 17:47

1 Answers1

0

According to the documentation .search() is actually more of a filter which works with string comparison (either straight or using regular expressions). You want to filter/search based on a numerical comparison.

Have a look at how you can add this custom filtering function at https://datatables.net/examples/plug-ins/range_filtering.html

Philip
  • 2,888
  • 2
  • 24
  • 36