create new tag
, view all tags

Sorting Lists in TWiki

2008-07-06 - 18:05:48 by VickiBrown in Usability
Where I work, we have started a page for "new people" in the department. People are added to the page as they join the group. Each person has a section for mini-bio and other information and there is a table of contents.

The problem: as the page gets larger, it's more difficult to find the entry for a given person. The TOC is ordered by when the person joined. It would be convenient to be able to sort the TOC alphabetically (it's just a list after all)

I started looking for ways to sort a list in TWiki. As long as I was at it, I figured I might as well look for a generalizable solution that can sort any bullet list.

I looked at Plugins.SpreadSheetPlugin but the sort functions want table cells. No tables here.

I figured JavaScript could solve the problem. I did a web search for JavaScript that sorts lists and found a very promising script written by Bruno Bornsztein (blog.feedmarker.com). The script worked well on simple bullet lists but needed some work to modify it for a TOC.

In particular, the script was finding the list by ID and TWiki TOCs don't have a unique ID :-( However, they do have a unique class :-) (providing, of course, that there is only one TOC on the page!)

I modified the JS to handle classes (using the named class to set an id on the list in question) and got it working. Then I handed it to Main.RichMorin for review and he said: you should put in a way to revert to the original order.

Well, duh. That was a bit trickier. I could just reload the page - but that's time consuming and would revert every list on the page.

So I asked around, got some help, and learned a few new JS tricks, and now lists are revertible to initial order as well as sortable in either ascending or descending order.

  • grapefruit
  • dog
    • spotted
  • boxcar
  • houseboat
  • aardvark
  • caterpillar

Sort it || Reverse sort || Initial order || Reload the page

You can see a more detailed writeup (with a TOC example) at cfcl.com/twiki/.../TWikiTutListSort.

The Javascript code is attached: list_sort.js


Have a look at FilterPlugin. It's FORMATLIST tag might fit your needs.

-- Michael Daum - 07 Jul 2008

Do a form and a page for each person and build an app around it.

-- Martin Cleaver MSc MBA - 08 Aug 2008


Topic attachments
I Attachment History Action Size Date Who Comment
JavaScriptjs list_sort.js r1 manage 5.3 K 2008-07-06 - 17:26 VickiBrown JS functions to sort a bullet list or TOC
Topic revision: r1 - 2008-07-06 - VickiBrown

Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Help
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.