Search function

Search function

juancarlos77juancarlos77 Posts: 7Questions: 3Answers: 0

at what time the function $ .fn.dataTable.ext.search.push is called?

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Any type Datatables is performing a search $ .fn.dataTable.ext.search.push is called. Essentially you are adding filtering capabilities to any search that is performed. Is there a specific filtering capability you are trying to achieve?

    Kevin

  • juancarlos77juancarlos77 Posts: 7Questions: 3Answers: 0

    Thanks kthorngren, I'm trying to filter a table by date range like this:

        $.fn.dataTable.ext.search.push(
            function(settings, data, dataIndex) {
                var startDate = $('#startDate').val();
                var endDate = $('#endDate').val();
                var invoiceDate = data[1] || 0; // Our date column in the table
    
                if ((startDate == "" || endDate == "") || 
                                     (moment(invoiceDate).isSameOrAfter(startDate) && 
                                     moment(invoiceDate).isSameOrBefore(endDate))){
                    return true;
                }
                return false;
            }
        );
    

    Imagine running when the datepicker changes like this:

    $('#dateRange').change(function() { invoiceDataTable.draw(); });

    But nothing happens, if you can help me ...

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Please put together a simple test case replicating your date data along with the search plugin. Then we will be able to help.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • juancarlos77juancarlos77 Posts: 7Questions: 3Answers: 0
    edited December 2018

    ok, enter in https:\www.alladin.7-soft.net

    The credentials are:

    demo@demo.com
    demo

    Once logged copies and paste this link to go to the page

    https://www.alladin.7-soft.net/v1.1.18320/account.php?optId=19

    it is a table of invoices which I want to filter by date range, customers and invoice status

    If you need something else, tell me. thank you for your help

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited December 2018

    I didn't pickup on this with your questions but you have "serverSide": true, which means that client side searching is not going to be used. Any Datatables searches performed will be sent to the ajax url defined by ajax option. Your server script is responsible for performing the search and responding with the correct data.

    Here is the server side processing docs:
    https://datatables.net/manual/server-side

    Kevin

This discussion has been closed.