[TW5] group by field

732 views
Skip to first unread message

Scott Kingery

unread,
Mar 2, 2014, 3:45:26 AM3/2/14
to tiddl...@googlegroups.com
I'm just getting started experimenting with TW5. What I want to do is have a field called subtopic and then have those grouped on a list.

The results looking something like:
Movies (main topic and title of tiddler)
Comedy (subtopic)
Drama (subtopic)

The following is the general idea but doesn't have the syntax to group.

<$list filter="[has[subtopic]sort[subtopic]]">
<h2><$view field="subtopic"/></h2><$link to={{!!title}}><$view field="title"/></$link><br>
</$list>
 
Can this be done?
Thanks,
Scott

Stephan Hradek

unread,
Mar 2, 2014, 4:49:49 AM3/2/14
to tiddl...@googlegroups.com
Does this example help?

My main tiddlers are tagged "sortexample" and have a field "order". The subtiddlers have a field "section", containing its parent's title, and a field "order".

http://skeeve.tiddlyspot.com/ tiddler: " topic and subtopic"

cmari

unread,
Mar 2, 2014, 4:38:30 PM3/2/14
to tiddl...@googlegroups.com
Hi Scott,

I was fiddling around with something similar yesterday.  In case it's of interest, here's the (far more rudimentary approach than Stephan's) approach I came up with.  Note that this doesn't make use of tags at all, it simply finds all the tiddlers that contain a field called subtopic, and then lists those tiddlers (alphabetically) by subtopic. You could of course sort the lists differently, and you could filter for a particular tag by adding, e.g., [tag[Movie], to the second list filter. I would have liked to be able to search for tiddlers tagged with the current tiddler's title, or even tag, but I don't know how to do that in any generic way, so I opted instead to use a unique field name in the tiddlers I wanted in my list. 

(Also, obviously, you could take out the styles; I was just seeing what I could do with the options that already existed).

<$list filter="[!is[system]has[subtopic]each[subtopic]sort[subtopic]]"><div class="tw-menu-list-item"><$link to={{!!subtopic}}><$view tiddler={{!!subtopic}} field="title"/></$link>
</div>
<$list filter="[subtopic{!!subtopic}sort[title]]">
<div class="tw-menu-list-subitem">

<$link to={{!!title}}><$view field="title"/> </$link>
</div></$list></$list>

cmari

Scott Kingery

unread,
Mar 3, 2014, 2:08:12 AM3/3/14
to tiddl...@googlegroups.com
Thanks everyone.
cmari, the each[subtopic] was the piece I was missing I think.

Additionally, I'm trying to do what you want as well by having the list search for tiddlers tagged with the current tiddler's title. I borrowed this: 
<$list filter="[is[current]tagging[]sort[title]]">

from http://www.giffmex.org/tw5mall.htm. It gets us a bit closer by I can't seem to get the syntax right to merge it in with what you gave me before.

aSpex Daemon

unread,
Mar 3, 2014, 1:21:05 PM3/3/14
to tiddl...@googlegroups.com
Hello Scott,
I made something similar to what you want to do. I used tags to group tiddlers in the menu.
Here is the link: https://dl.dropboxusercontent.com/s/j0yzo2ap0ne90hz/tw5a10.tagmenu.html. See the TagMenu tiddler.
I hope this will help you.

Message has been deleted

Scott Kingery

unread,
Mar 4, 2014, 4:03:14 PM3/4/14
to tiddl...@googlegroups.com
Well, I'm almost there.

When you look at the example you'll see the issue. It is mostly working but things aren't showing up as they should. I've outlined it in the Problems tiddler you'll see when you look at the example.

My code:
<$list filter="[is[current]tagging[]has[subtopic]each[subtopic]sort[subtopic]]">
<div class="tw-menu-list-item">
<$view field="subtopic"/>
</div>
<$list filter="[subtopic{!!subtopic}sort[title]]">
<div class="tw-menu-list-subitem">
<$link to={{!!title}}><$view field="title"/> </$link>
</div></$list></$list>

Stephan Hradek

unread,
Mar 4, 2014, 4:24:15 PM3/4/14
to tiddl...@googlegroups.com
\define MyFilter()
[tag[$(MyTag)$]subtopic{!!subtopic}sort[title]]
\end

<$set name="MyTag" value={{!!title}}>

<$list filter="[is[current]tagging[]has[subtopic]each[subtopic]sort[subtopic]]">
<div class="tw-menu-list-item">
<$view field="subtopic"/>
<
/div>
<$list filter=<<MyFilter>>>

<div class="tw-menu-list-subitem">
<$link to={{!!title}}><$view field="title"/
> </$link>
</
div></$list></$list></$set>


Scott Kingery

unread,
Mar 4, 2014, 4:43:31 PM3/4/14
to tiddl...@googlegroups.com
Thanks for the quick response, Stephan! I've updated my example wiki and changed the Books Tiddler to include your code for future reference.

cmari

unread,
Mar 16, 2014, 8:30:00 PM3/16/14
to tiddl...@googlegroups.com
So much seems possible with filters and sorting that I tried - but failed - to find a way to sort the first level items (in this case, the subtopics) according to some other criterion than alphabetically by title.

Am I asking for too much, or is there some way to do this?

(For visualization of what I'm trying to describe: in http://cmaritw5.tiddlyspot.com/ , would it be possible to sort the items in MyList by the level of their importance, from most to least?  I do realize the easy way would be to add numbers in front of the importance level, but I'm looking for more flexibility).
cmari

Stephan Hradek

unread,
Mar 17, 2014, 12:23:14 AM3/17/14
to tiddl...@googlegroups.com
  1. Create for each importance a tiddler with the importance's name and the importance's value as a field
  2. Make the first list over these tiddler, sorted by importance value field
  3. Make the inner list find those tiddlers havig the importance's name in their field
Message has been deleted

Stephan Hradek

unread,
Mar 17, 2014, 4:02:54 AM3/17/14
to tiddl...@googlegroups.com
I posted something for Mr. Daemon here but it vanished? How could that happen?

Stephan Hradek

unread,
Mar 17, 2014, 4:26:56 AM3/17/14
to tiddl...@googlegroups.com

\define MyFilter()
[tag[$(MyTag)$]itemtype[$(itemtype)$]sort[title]]

\end

<$set name="MyTag" value={{!!title}}>

 
<$list filter="[has[impval]nsort[impval]]">
   
<$set name="itemtype" value={{!!title}}>
     
<div class="tw-menu-list-item">
       
<$link><$view field="title"/></$link>

     
</div>
      <$list filter=<<MyFilter>>>
        <div class="tw-menu-list-subitem">
          <$link to={{!!title}}><$view field="title"/
></$link>
       
</div>
      </
$list>

   
</$set>
  </
$list>
</$set>


 The problem with sorting in your case is (I guess): "each" does not switch to your "itemtype", meaning: You don't have a list containing "least important", "most important"... but you will have one tiddler having one of the importances.

cmari

unread,
Mar 17, 2014, 11:35:23 AM3/17/14
to tiddl...@googlegroups.com
Hi Stephan,
Sorry, my example was put up too quickly (it was actually taken from straight from your example, posted at http://dl.dropboxusercontent.com/u/118970/wiki/tw5tribalknowledge.html.  But I had forgotten I'd already used MyList for testing other macros elsewhere in the TW).  I'm now using "ImportantList" instead of "MyList" at http://cmaritw5.tiddlyspot.com

But what I'm still clueless about is how to actually write the filters to create the outer and inner lists. 
cmari

cmari

unread,
Mar 17, 2014, 11:37:56 AM3/17/14
to tiddl...@googlegroups.com
Actually, I'm even more baffled now, because in my own local TW, I can click on "important" in the list and it will open the tiddler called "important".  That obviously doesn't work in my example on Tiddlyspot.
cmari

Stephan Hradek

unread,
Mar 17, 2014, 12:42:47 PM3/17/14
to tiddl...@googlegroups.com
Why don't you check my reply then. I'm pretty sure you can understand that and apply it to your real example.

cmari

unread,
Mar 17, 2014, 2:49:48 PM3/17/14
to tiddl...@googlegroups.com
Hi Stephan, you are right of course - I had only seen your message with the three-step description, not the reply in which you included the tiddler contents.
Your solution works perfectly, thanks very much!
cmari

Boazter

unread,
Jun 13, 2021, 5:05:55 PM6/13/21
to TiddlyWiki
I have a question about taking this one step further, but first, I just want to say thank you, thank you, thank you for this thread (original poster and everyone who helped). 

I was able to take this code and incorporate it into a grocery list that I'd developed years ago and which I've been wanting to tweak. This code allowed me to group my list by the aisle. (In actuality it's more like general areas of the store.) It works great and I'm absolutely over the moon about it as I had gone down many rabbit holes before I found what I was looking for! 

Now I'm wondering about tweaking it further so that it doesn't show the name of an aisle when there are no items on the list for that particular trip.

Let me 'splain:

I have dozens of tiddlers of various grocery items, each with a field called "aisle" with values like "bakery", "dairy", "frozen", "meats." I have a full list to choose from of potential grocery items and clicking an item tags them with "$purchase" (meaning "to be purchased") and they move to the current shopping list. 

With help from this thread I developed the code below to show the current shopping list grouped by aisle. As I shop, checking an item on that list tags it as "$purchased" (not to be confused with "$purchase" above!) and drops it from the list.

Here is the code:

<$list filter="[has[aisle]each[aisle]sort[aisle]]">
<div class="tw-menu-list-item">
<$view field="aisle"/>
</div>
<$list filter="[!tag[$purchased]tag[$purchase]aisle{!!aisle}sort[title]]">
<div class="tw-menu-list-subitem">
<$button class="tc-btn-invisible">
<input type="checkbox"/>
<$action-listops $tags="$purchased"/>
</$button> <$link to={{!!title}}><$view field="title"/></$link> 
</div></$list></$list>

The above might produce a list something like this:

bakery
  bread
  cookies
dairy
  milk
  cream
frozen
meats
  chicken
  sausage
etc.

As you can see, there are items under the "aisle" headers for "bakery", "dairy" and "meats"; but none under "frozen". What I want is, if there are no items from the frozen aisle (aisle="frozen") tagged with "$purchase", then suppress the header (in this case "frozen") from appearing on the list. That is, only show the header for "aisles" that contain items tagged with "$purchase". 

I thought I could fix this by adding "tag[$purchase]" to the first filter but doing so caused my list to completely disappear.

My skill level is pretty basic but improving. Is there an easy fix for this? Am I missing something obvious? 

Best regards and thank you for any help.

mr

TG

unread,
Jun 15, 2021, 11:11:01 AM6/15/21
to tiddl...@googlegroups.com
All,

Just wanted to follow up on this since I appear to have stumbled across the solution. My problem appears to have been the order in which I placed the tag filter. I had noted:

"I thought I could fix this by adding "tag[$purchase]" to the first filter but doing so caused my list to completely disappear."

I mulled it over and decided to play around with that again. I found that by placing it at the front of the filter I was able to get the results I wanted, before I had placed it _after_ the aisle tags. 

The following code worked for me:

<$list filter="[tag[$purchase]has[aisle]each[aisle]sort[aisle]]">
<div class="tw-menu-list-item">
<$view field="aisle"/>
</div>
<$list filter="[!tag[$purchased]tag[$purchase]aisle{!!aisle}sort[title]]">
<div class="tw-menu-list-subitem">
<$button class="tc-btn-invisible">
<input type="checkbox"/>
<$action-listops $tags="$purchased"/>
</$button> <$link to={{!!title}}><$view field="title"/></$link> 
</div></$list></$list>

This dropped the "frozen" category from my list in the example. 

Best regards, 

mr

--
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/XxLT8zJqHYM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/bf28d22d-61da-459e-88de-238faa5463f4n%40googlegroups.com.

scot

unread,
Jun 15, 2021, 4:42:56 PM6/15/21
to TiddlyWiki
Hello Boazter
I think this discussion may interest you - It includes a groceries TW from Mark S.


groceries tw here

Scot

TG

unread,
Jun 15, 2021, 10:45:39 PM6/15/21
to tiddl...@googlegroups.com
Very nice! There are some good things for me to explore here. It's interesting to see the similarities and the very different paths we took. Of course, my skill isn't up to par but it is fun learning with an actual project. I still have some tweaking to do but perhaps I'll share mine once I've got something halfway decent. Thank you for sharing this.

scot

unread,
Jun 16, 2021, 9:05:06 AM6/16/21
to TiddlyWiki
Glad it helped.
Thanks goes to Mark S. for all his work.
Regards,
Scot
Reply all
Reply to author
Forward
0 new messages