"in" filter operator, or better AND logic.

191 views
Skip to first unread message

ma...@mklauber.com

unread,
Oct 26, 2020, 12:43:00 PM10/26/20
to TiddlyWiki
Hey all, I'm trying to figure out how to handle an issue I've got coming up.  

I have a dataset I'm storing as tiddlers, with each field as a column.  I'm trying to implement filters on the dataset using <$select> widgets that allow selecting multiple values.  I'm trying to create a filter that for each tiddler in the dataset checks if `{{!!field}} is contained in {{Selected!!field}}` i.e. is the tiddlers value in the allowed values.

I figured out how to do this once, by flipping my filter around and saying `[[Selected]contains:field{!!field}]`  But I can't use the `+` symbol to AND these together, as the input is replaced instead of unioned with the preceding filter.

Does anyone know a better way to implement an `value IN list` filter, or a better way to and things?  

p.s. I'm trying to avoid multiple loops for ANDs, as I want to be able to filter on arbitrary fields.  

Thanks,
Matt

TW Tones

unread,
Oct 27, 2020, 12:57:02 AM10/27/20
to TiddlyWiki
Matthew,

I am sure I can help you but to do it from your last post is a little tricky. 
  • Can you give a minimal case, perhaps that works on tiddlywiki.com
  • Doing this this I find I often find my own solution.
  • If anyone provides a solution on the minimal case you and other readers will likely learn even more.
Regards
Tones

ma...@mklauber.com

unread,
Oct 27, 2020, 8:56:53 AM10/27/20
to TiddlyWiki
Here, I've placed my current dataset (D&D Creatures) and my attempts at to achieve it in the attached file.  Thanks for taking a look.  I suspect that with 5.1.23, I'll be able to use the `filter` operator to solve this problem, but I'd love a backwards compatible option for people.
problem.html

ma...@mklauber.com

unread,
Oct 28, 2020, 11:58:17 AM10/28/20
to TiddlyWiki
I ended up writing a `in` filter operator, which can compare a field on the input tiddler to a TextReference to a list, and pass it through if it's in the list.  The code is here https://github.com/mklauber/tiddly-in-filter, and it's available in my plugin library here: https://mklauber.github.io/tw5-plugins/

Between that and the wikify macro to build up my filter runs, I was able to get things working.

Reply all
Reply to author
Forward
0 new messages