Dynamic filter with "all" option

117 views
Skip to first unread message

Brian Gates

unread,
May 16, 2015, 10:11:17 PM5/16/15
to tiddl...@googlegroups.com
I have spells tagged as belonging to certain classes.  I want to create a display which list of spells with a dropdown to filter by a class (or not).

<div class='input'>
 
<label>Filter by Class</label>
  <$select field='selected_class' default='All'>
   
<option value='All'>All</option>
    <$list filter='[tag[Class]]'>
      <option value=<
<currentTiddler>>><$view field='title'/></option>
    </$list>
  </$select>
</div>


<ul>
  <$list filter="[tag[Spell]tag{!!selected_class}]">
   
<li>{{!!title}}</li>
  </$list>
</ul>


I can't figure out how to get the "all" portion to work.  I can't find seem to do tag[*], nor can I figure out how to dynamically construct a query string to be used as a filter expression (it seems I can not dynamically select operators, only parameters).

Any help appreciated!

Eric Shulman

unread,
May 16, 2015, 11:01:22 PM5/16/15
to tiddl...@googlegroups.com
Hmm.... 

Assuming that all spells are tagged with "Spell" plus some unique class tag, you could just use "Spell" as the value for the "all" option, and just filter by the selected_class value, like this:

<div class='input'>
 
<label>Filter by Class</label>

  <$select field='selected_class' default='All'>
    <option value='Spell'>All</option>
    <$list filter='[tag[Class]]'>
     
<option value={{!!title}}>{{!!title}}</option>
    </$list>
  </$select>
</div>
<ul>
  <$list filter="[tag{!!selected_class}]">
   
<li>{{!!title}}</li>
  </$list>
</ul>

That should get you what you want.  Let me know how it goes...

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

Brian Gates

unread,
May 16, 2015, 11:09:12 PM5/16/15
to tiddl...@googlegroups.com
That does it!  Clever.  Thank you :)

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/FREkHZwIyG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/c02f9594-2b77-4421-97f4-fc874fba0a90%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Brian Gates

unread,
May 16, 2015, 11:14:20 PM5/16/15
to tiddl...@googlegroups.com
Am I correct in assuming there's no wildcard option for the parameter?  Like, if I wanted to filter by a field instead, how might I accomplish this?

Eric Shulman

unread,
May 17, 2015, 12:55:07 AM5/17/15
to tiddl...@googlegroups.com
On Saturday, May 16, 2015 at 8:14:20 PM UTC-7, Brian Gates wrote:
Am I correct in assuming there's no wildcard option for the parameter?  Like, if I wanted to filter by a field instead, how might I accomplish this?

There's lots of filter operators.... 


To filter by a field, use:
   field:fieldname[value]

There is also a short form:
   fieldname[value]

The short form is most typically used.  For example, "title[SomeName]".

The full syntax (including the "field:") is needed when the fieldname could be confused with another filter operator name.

For example, there is a filter operator called "sort[fieldname]" that sorts the list based on the value of the specified field.

But if you have a *field* named "sort", using "sort[value]" would be ambiguous, so you have to  use "field:sort[value]" to make the meaning clear.

Brian Gates

unread,
May 17, 2015, 1:03:42 AM5/17/15
to tiddl...@googlegroups.com
Right, but if I wanted to filter by a Spell field "school", and I wanted an "all" option, what might I do?  I don't have the same luxury of necessarily specifying Spell as the tag, I have to fill in something for the filter.

e.g. school[Abjuration], might result from school{!!school_filter}, but how would I handle {!!school_filter} of "All"?, I can't do school[*], or the like, can I?

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/FREkHZwIyG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.

Jed Carty

unread,
May 17, 2015, 2:30:44 AM5/17/15
to tiddl...@googlegroups.com
The most straight forward way is to have a reveal widget that shows the list of everything when 'all' is selected, and shows the list for the specific tag when any other option is selected. You may also be able to make a macro that returns tag[SomeSchool] when the field isn't 'all' and returns an empty string when the field is 'all'. It is too late for me to think about the second option too much now. I think I have some example in one of the plugins I made. I may remember in the morning.

Eric Shulman

unread,
May 17, 2015, 3:20:12 AM5/17/15
to tiddl...@googlegroups.com
On Saturday, May 16, 2015 at 10:03:42 PM UTC-7, Brian Gates wrote:
Right, but if I wanted to filter by a Spell field "school", and I wanted an "all" option, what might I do?  I don't have the same luxury of necessarily specifying Spell as the tag, I have to fill in something for the filter.

To get all tiddlers that has a "school" field, regardless of the value, you would need to use the "has[school]" filter instead of "school<!!schoolfilter>".

You can accomplish this by using a pair of <$reveal> widgets that uses the {{!!school_filter}} input as the state:

<$reveal type="match" text="All" state="!!school_filter">
<$list filter="has[school]">
   ...
</$list>
</$reveal>
<$reveal type="nomatch" text="All" state="!!school_filter">
<$list filter="school{!!school_filter}">
   ...
</$list>
</$reveal>

Eric Shulman

unread,
May 17, 2015, 3:24:45 AM5/17/15
to tiddl...@googlegroups.com
errata: I left out the outer square brackets on the filter="..." bits:

it should have been this:


<$reveal type="match" text="All" state="!!school_filter">
<$list filter="[has[school]]">
   ...
</$list>
</$reveal>
<$reveal type="nomatch" text="All" state="!!school_filter">
<$list filter="[school{!!school_filter}]">
   ...
</$list>
</$reveal>

-e
 

Brian Gates

unread,
May 17, 2015, 1:46:34 PM5/17/15
to tiddl...@googlegroups.com, tiddl...@googlegroups.com
Thanks again, that should do the trick. I ended up promoting the fields to tags in any event. 



--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/FREkHZwIyG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.

Brian Gates

unread,
May 17, 2015, 1:49:45 PM5/17/15
to tiddl...@googlegroups.com, tiddl...@googlegroups.com
Ok one more crazy question. If I wanted checkboxes to show/hide spells of certain levels 1-9, is there anything I could do there? Level exists as tag and field.

Would love to be able to sort across levels also. 

So, show spells level 1,2, and 3 sorted by name.



On Sun, May 17, 2015 at 12:25 AM, Eric Shulman <elsd...@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages