Auto-filter on load

Auto-filter on load

nlaslettnlaslett Posts: 9Questions: 0Answers: 0
edited June 2009 in General
Excellent product. As always, I'm impressed. Here's one small pseudo-bug / feature request:

(This is only true for WebKit based browsers: Chrome and Safari)

When you go "back" in the browser to a page with a filtered dataTable, the filter value is still in the Search form field but the filter event hasn't been triggered. You have to go into the Search box and type something (e.g. a space) to trigger the filter event. I know I can manually trigger the filter event manually using the API, but it would be nice to automatically do this during initialization, just in case there is a value lingering there from the browser.

This is different from specifying an initialization filter value using the API; I know that works. I'm talking about when the browser populates the field when you go "back".

Thanks,
Neil

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Neil,

    Thanks for posting about this. Probably a 'feature' in Webkit, but fairly frustrating for this kind of things. I've put a fix into the current development version which changes how this field in initialised, such that the filed is cleared when you press the back button (unless you have state saving on or set an initial filter!) - so it shouldn't crop up now, but the value of the field is lost on the back button. This seems the best approach over all (same across browsers). I'll release this with a couple of other small changes soon.

    Regards,
    Allan
  • nlaslettnlaslett Posts: 9Questions: 0Answers: 0
    Thanks Allan!

    One related question: Is there really no "name" or "id" value for the search field? I'm referencing it (with jQuery) like this: $(".dataTables_filter input").val()

    That works, but it seems odd that there isn't an id for the search field itself. How are you reading the value and event triggers?

    Neil
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Neil,

    Your selector is the "correct" (one of many!) ways of getting the input element. The reason I didn't put an ID on the input was that there was simply no need for it - that selector is as good as an id (a tiny bit slower I admit, but not so much that anyone would ever notice).

    The way DataTables reads this input internally is through a selector much like that ('$("input", nFilter);' to be exact, where nFIlter is the wrapping div) - and then an event handler is placed on that for keyup.

    If you are interested, _fnFeatureHtmlFilter() is the internal function which does this. It has been slightly modified now from the current release though :-)

    Regards,
    Allan
This discussion has been closed.