Range search in DataTable for a particular column

Range search in DataTable for a particular column

lovedhakalovedhaka Posts: 6Questions: 4Answers: 1

Hello,
I have a column known as Days Extracted i need a way where in i can get the Javascript (not the jQuery) code which i can use to achieve this.
I looked at the following example
https://datatables.net/examples/plug-ins/range_filtering.html
I need to do exactly this thing but through a select box and Javascript .
PFA the image.
Here is my code below.

  var columnDays = this.api().column(12);  //12 is the column index for Days Extracted
            $('<select><option value="">--Select Days Extracted--</option><option value="0">0 TO 5</option><option value="6">6 TO 10</option><option value="11">11 TO 15</option><option value="16">16 TO 20</option><option value="21">21 TO 25</option><option value="26">26 TO 30</option></select>')
                .appendTo($('#filterDays'))
                .on('change',function () {
                   var min = parseInt($.fn.dataTable.util.escapeRegex(
                       $(this).val()
                   ));
                   var max = min + 5;
                       if(min == 0){
                           max = 6;
                       }
               columnDays.search().draw(); // i need help here..

This question has an accepted answers - jump to answer

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    You have to provide an argument within the column().search()

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    Alternatively, give YADCF a look.

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    Actually range filtering is a little bit beyond the column().search() method at the moment I'm afraid. You need to use a search plug-in. It is a function that you control, so it can get its inputs from anywhere, including select elements, but you need to define its logic and where it gets data from.

    Allan

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    But if you explode that range into an array, 0-5 becomes [0,1,2,3,4,5], column().search() can accept that.

  • osorioaosorioa Posts: 1Questions: 0Answers: 0

    Hey Allan, how to manage range filtering in server-side processing mode?

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    You would need to have your server-side script accept the range values and apply a suitable condition to the query it uses. You can use ajax.data to send extra values to the server.

    Allan

This discussion has been closed.