rejetto forum

Can I set the filter programatically?

skb · 4 · 2874

0 Members and 1 Guest are viewing this topic.

Offline skb

  • Occasional poster
  • *
    • Posts: 50
    • View Profile
I hope this is basic, but I guess I don't really get how it works. I would like to generate a particular ?filter string in response to a user button press and apply it to the current folder view.

In my application, which is based on the standard hfs.tpl, our data files are named in a particular way, which makes it useful to show only certain subsets based on the names. Rather than making the users type ?filter lines into their address bar, I'd like to have buttons and scripts for some common filters, similar to the idea of the "Select" box of the template, e.g. A button to show all files, which would clear the ?filter from the URL; a button to filter by specific file name codes; and also a "Mask" button for the user to enter the pattern they want, which gets expanded to a filter line.

BUT: what do I do with my filter string to refresh the page with that filter added to the URL? Can I do it from Javascript, or from a HFS macro, or either way?

E.g. for project code "A31", I'd prompt the user for the code, and make a filter string like "?filter=BD_A31_*" . Once I've generated that string, how do I apply it to the current folder view?

Thanks for any hints and pointers!
Steve




Offline skb

  • Occasional poster
  • *
    • Posts: 50
    • View Profile
Never mind! Turns out to be basic Javascript, nothing custom to hfs:

window.location.search

All set. :P



Offline skb

  • Occasional poster
  • *
    • Posts: 50
    • View Profile
Thanks for the additional info.

For my simple case, when they click my "Apply Filter" button, then in the Javascript click handler, I build the ?filter string as variable newFilterStr from the pieces the user had entered in some custom fields, and then apply the resulting filter by using: window.location.search = newFilterStr .

When they click my "Clear Filter" button, I just use:  window.location.search = "" , and this clears the filter from the URL. 

(Note that setting window.location.search also clears any other options such as custom sort orders and stuff, but I don't worry about that. If you cared, you could read the existing value of window.location.search and modify it, but it is easier to just replace it.)

Also, setting window.location.search causes a page reload, which resets the custom fields that the user used to enter their desired filter back to default values. This makes it annoying to edit a filter you've applied, as the values you previously entered are gone. So, I use a jquery "$( document ).ready" function, which is called at page load, to parse the filter string (if any) and reset my fields to the id values that generated it.

(Again, all my fancy filtering depends on the fact that we use specific character positions in our data file names as fields with specific meanings, so we can filter on these character positions to show particular subsets of our data files. None of this would be any use for general file upload/download service.)

In any case, I'm all set on this topic.