Filter column just in time using serverSide

Filter column just in time using serverSide

bor1904bor1904 Posts: 5Questions: 1Answers: 0

Hi,
I try to implement column filtering without pressing Enter key, but I cant find predefined option for this. I use serverSide processing.
Pressing enter is not comfortable each time.

Can somebody help me ?

thx!

This question has an accepted answers - jump to answer

Answers

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

    Please post the code you have for the column search.

    Kevin

  • bor1904bor1904 Posts: 5Questions: 1Answers: 0

    Hi,
    I dont have any special code dedicated for this.
    I want to achive global effect on all columns.

    Initiation code:

        processing: true,
        serverSide: true,
        pageLength: 25,
        autoWidth: false,
        order: [[ 0, "desc" ]],
        ajax: 'get-invoices',
    
  • kthorngrenkthorngren Posts: 21,305Questions: 26Answers: 4,947

    Maybe I don't understand the issue but by default Datatables sends an Ajax request to the server for each key stroke in the Global Search box. You can see this in this example:
    https://datatables.net/examples/data_sources/server_side.html

    Is this the behavior you are trying to achieve?

    Kevin

  • bor1904bor1904 Posts: 5Questions: 1Answers: 0

    I know that the global search box working on every keypress but I want to achive the same effect on column search boxes.

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

    Like I asked before please post your code for the column searches. It is not a default code that comes with Datatables. Likely you will need to change the event handler from using 'change' to 'keyup'.

    Kevin

  • bor1904bor1904 Posts: 5Questions: 1Answers: 0

    I dont have custom modyfication in this area but i used plugin.
    https://datatables.yajrabox.com/eloquent/multi-filter-select

    I think that the normal datatables implementation have column search triggered on keypress but default solution for column searching witch serverSide procesing is triggered on change.

    I try to change this behavior to "on keypress"

  • kthorngrenkthorngren Posts: 21,305Questions: 26Answers: 4,947
    Answer ✓

    This is the custom code it has for the column search:

           initComplete: function () {
                this.api().columns().every(function () {
                    var column = this;
                    var input = document.createElement("input");
                    $(input).appendTo($(column.footer()).empty())
                    .on('change', function () {
                        column.search($(this).val(), false, false, true).draw();
                    });
                });
            }
    

    You can change line 6 to use keyup event, for example:
    .on('keyup', function () {

    Kevin

  • bor1904bor1904 Posts: 5Questions: 1Answers: 0

    ok, Im blind :/

    thank U!

This discussion has been closed.