You are here: CFCL Wiki>Help Web>WikiTut>WikiTutSortLists (09 Feb 2011, vlb)Edit Attach

Wiki Tutorial:

Sort a List

Sometimes, you might want to sort a list alphabetically. You can do this dynamically with JavaScript. Include the following line in your page
   <script type="text/javascript" src="%PUBURL%/Help/WikiTutSortLists/list_sort.js"></script>
to access the JavaScript function.


Why would you want to sort a TOC? A TOC provides quick access into the page, where each item links to a section header. If the number of headers is large, it may be difficult to find the particular one you're looking for in the TOC. Sorting turns a TOC into an index.

Try it

Sort TOC

Sort TOC (Descending)


Grapefruit are citrus fruits.


Apples are crunchy.


Fruit contains carbohydrates.


Bananas are good on cereal.

List example

  • grapefruit
  • dogs
    • spotted
  • boxcar
  • houseboat
  • aardvark

Try it

Sort List Example

Sort List Example (Descending)

The Code

Sort a TOC

 <a href="javascript:void(0);" onclick="list_sort(this)" is_toc='true' >Sort TOC </a>
 <a href="javascript:void(0);" onclick="list_sort(this)" is_toc='true' order="reverse">Sort TOC (Descending)</a>

Sort a typical bullet list

 <a href="javascript:void(0);" onclick="list_sort(this)" class="Foo">Sort List Example</a>
 <a href="javascript:void(0);" onclick="list_sort(this)" class="Foo" order="reverse">Sort List Example (Descending)</a>

-- VickiBrown - 04 Jul 2008

Topic attachments
I Attachment Action Size Date Who Comment
list_sort.jsjs list_sort.js manage 4 K 18 May 2009 - 17:58 UnknownUser JavaScript functions for sorting a list (bullets or TOC)
Topic revision: r4 - 09 Feb 2011, vlb
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email