.search().draw() - Custom Date Filter

.search().draw() - Custom Date Filter

goktuginal41@gmail.comgoktuginal41@gmail.com Posts: 57Questions: 22Answers: 0

Hello everyone,

I have custom date filter. I want to see the rows between min and max dates on the screen. I'm using server-side processing. When I search for a certain value, I can write it in the search function and display the table, but how can I use the search function between two dates? Thanks in advance.

var min = new Date()
var max = new Date()
$('#search_date').click(function () {
   dtable.column(1).search().draw() 
});

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Try this Date range search plugin. You can see a running example of numeric range search here.

    Kevin

  • goktuginal41@gmail.comgoktuginal41@gmail.com Posts: 57Questions: 22Answers: 0

    As I know, DataTable.ext.search.push function is not working with server side processing, no?

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    You are correct, that is for client side processing. You can send the date range values using ajax.data as shown in this example. You can use just draw() to have a server side processing request sent to the server, for example:

    $('#search_date').click(function () {
       dtable.draw()
    });
    

    You server script will need to fetch the parameters sent via ajax.data to filter the search results.

    Kevin

  • goktuginal41@gmail.comgoktuginal41@gmail.com Posts: 57Questions: 22Answers: 0

    Thank you. It really helped me. I have one more question. How can I call d.myKey parameter in click function?

    data: function (d) {
                d.myKey = 'myValue';
            }
    
  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    You wouldn't access the d.myKey value within your Javascript code. It is a parameter sent via ajax to the server. If you have two date range inputs, similar to this example you would access them using something this $("#min").val();. Your ajax option would look like this:

        ajax: {
            url: 'scripts/server_processing.php',
            data: function (d) {
                d.date_min = $('#min').val();
                d.date_max = $('#max').val();
            }
        },
    

    In your click function you will access the values using $('#min').val(); and $('#max').val();.

    Kevin

Sign In or Register to comment.