Gathering all search fields for aka

Gathering all search fields for aka

chuckgchuckg Posts: 17Questions: 7Answers: 0

http://live.datatables.net/wixiguze/1/edit

Me again with a similar question.
Situation:
Server side ajax requests therefore search: {"return": true} is set
also setup using "Individual column searching (text inputs)"
DataTables by default only sets search() for the field where the 'enter' occurs ignoring all changes on any other input field.

Yesterday I learned how to get a popup to access the Search field before it triggers draw()
Today I need to do somewhat the opposite
In the above example link do the following:
1. on Position column enter "eng" on the input field at the bottom of the column. Do NOT press enter.
2. in the Search field enter "br" and press enter

The resulting search uses only the "br" to search and ignores "eng"

I have it set up so the if one presses 'enter' on a column search field, all the other column search fields set for a search() before the draw()
It is unclear how to do that for the Search field.
Is there an event I can't find documentation for?
Will it make a mess if I try to catch keypress 13 on the Search field?

It seems odd that there isn't a way to tell DataTables all the fields it needs to gather for an AJAX request.
Just defaulting to one seems odd. One can't expect users to press enter on each field and even if they did that would not be economical.
Having to manually gather the input data from all the other input fields on every darn input field also seems wasteful and prone to bugs if changes are made.
Having the browser do a local search on every key press is nice but it seems like server side processing potentially requires jumping through a lot of hoops... or I just can't find it in the docs.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 17,689Questions: 25Answers: 4,197
    Answer ✓

    First you have two initComplete configuration objects. Only one will be used. I think with Javascript the last object with the same name will be used.

    This event handler is never executed when only pressing enter on the global search input:

    $('input', this.footer()).on('keypress', function (ev) {
    

    Sounds like you should either create your own global input and remove the one Datatables displays with the dom option. Or take over the keyup click event the Datatables uses with the global search input. The latter is easier and is demonstrated here:
    http://live.datatables.net/wixiguze/2/edit

    I created a function to setup all the searches that is called by both the $('input', this.footer()).on('keypress' handler and the customer keyup handler. Also I commented out the search: {"return": true}, option

    Having to manually gather the input data from all the other input fields on every darn input field also seems wasteful and prone to bugs if changes are made.

    These are custom inputs that Datatables has no knowledge of so there are no options within Datatables to cleanly handle this. However you could improve this by using a loop to loop through all the inputs similar to how you create the inputs. Use the index parameter of the jQuery each() method to use as the column index. Use HTML5 data attributes to store the column number in the input which is then used for the column().search() index. See this example:
    http://live.datatables.net/hafotuqa/1/edit

    EDIT:

    Will it make a mess if I try to catch keypress 13 on the Search field?

    No, i forgot to add this but you can in the keyup event.

    Kevin

Sign In or Register to comment.