server-side with Individual column searching (text inputs)

server-side with Individual column searching (text inputs)

rodolphenrodolphen Posts: 18Questions: 4Answers: 0

Hello,

I use server side and I want to add 'Individual column searching (text inputs)' like
https://www.datatables.net/examples/api/multi_filter.html

It seems basic, but, when i enter a keyword, it makes several draw, so several ajax request instead of one. (same number of request os number of columns) and my keyword is sent into each column in the request.

Is anyone have an idea?

Regards,

Rodolphe

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Hi Rodolphe,

    It sounds like what might be happening is that the event handler is being bound to all inputs on every iteration of the loop that is being used to assign it in the first place.

    I've created this little example which demonstrates how it might be done: http://live.datatables.net/piqidoqo/1/edit . One key element is to use the initComplete callback - this is important for Ajax sourced tables since they are of course asynchronous by definition.

    Allan

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    You can also check my yadcf plugin for datatables , here is the server side showcase page among others it have lots of filter types, filter_delay and many more options.

  • rodolphenrodolphen Posts: 18Questions: 4Answers: 0

    Hi Allan,

    Ahhh... Thank you very much, it works!!

    Best regards,

  • bweith1bweith1 Posts: 5Questions: 0Answers: 1

    This works, but it still seems to fire an event for every column in the table when a single search value changes. I'm using a Servlet to filter data on the server side.

  • rodolphenrodolphen Posts: 18Questions: 4Answers: 0

    Hello,

    Allan's solution work fine with me, it fires only one request.
    I change this to do only one request by keywork and not at each letter :

            $('input', this.footer()).on('keydown',  function(e) {
             if (e.keyCode == 9 || e.keyCode == 13) {
                  if (that.search() !== this.value) {
                    that
                      .search(this.value)
                      .draw();
                  }
             }
            });
    

    Regards,

    Rodolphe

  • musinikmusinik Posts: 22Questions: 5Answers: 1
    edited January 2016

    @daniel_r I didn't succeed to implement your plugin normally.
    What I liked is that it works in pair with standard search, complementing it. An "AND" condition.
    I had problems with visualization. I downloaded several jQuery plugins, while tried to make it work.

    But how it works on your page, the functionality itself, is amazing!!

    I will start now implementing bootstrap-selectpicker (it looks great) with multiselect as a dropdown for the fields. I think I will take coding lessons from your plugin. Thanks for your work!

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    @musinik, thanks, yadcf provides api for easy integration with any third party select plugin. And all the source code of the yadcf plugin and the showcase are available on github.

This discussion has been closed.