DataTables logo DataTables

Custom per-column filtering on server-side
  • Hello allan and others,

    I'll start by explaining what I have done so far:
    I have a input text box on top of each column, people can enter their text fragments there.
    The server-side is prepared to do some LIKE queries against our database.

    Now I'm a bit unsure after reading a bit source code and some API documentation regarding the filter functions. Filtering on the database may took up to a few seconds because of many columns, not limited number of filterings and somewhat large number of rows, so type-ahead, or even column by column filtering is not applicable here, our customer needs to have a button to start the filtering manually. Is there some internal function or variable I can access to store the filter-settings or should I work arround datatables this time, and implement that via a custom array of Post parameters and a merge with datatables default one in my fnServerData?

    BTW: we're approximately 80% done with integration of dataTables and I want to say it one more time: we love it! I'll talk to our people to do some donation by february or march for your great work.
  • Hi Jens,

    When you say "button to start the filtering manually", I'm not sure what you mean. From a Javascript point of view, filtering in DataTables revolves around the fnFilter function. You pass it what you want to filter on (so it can be a single character, or a full string or whatever) and this will then be sent to the server as there parameter sSearch_{column-index}, at which point the server can do column based filtering. My example PHP script should include an example of how to do this on the server-side.

    Does that answer your question?

    Regards,
    Allan
  • Hello Allan,

    the problem I have is that fnFilter takes one column, and then does the filtering/the request to the server. What I like to do is having the input boxes without this "automatic request sending". Let's take this one for example:

    http://datatables.net/examples/api/multi_filter.html

    I would like to enter values in the column, and then start the filtering request manually, so I can send all sSearch_ in the first request. Hopefully this is more clear now.

    Thanks,
    Jens
  • Hi Jens,

    Right, so you want to remove the 'keyup' event handler. So you can do this quite easily - in the example you can see I've got "$("tfoot input").keyup( function () {" - what you want to do instead is to submit your search data to fnFilter when the user clicks on a button or hits return, or whatever you want the interaction to be. It's all about how you call fnFilter - once that has been called, then the filter will occur.

    Regards,
    Allan
This discussion has been closed.
All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.