Dynamic Ordered List

Last modified by Thomas Mortagne on 2026/02/26 15:38

cogControls for managing an ordered list of objects attached to a document
TypeXAR
Category
Developed by

Andreas Jonsson

Rating
0 Votes
LicenseGNU General Public License 3

Success

Installable with the Extension Manager

Description

This application provides a velocity macro that in inline editing mode renders controls for adding, removing objects to a list and rearranging the order of the items in the list.

Usage

  1. Define a class for the objects that will constitute the list.
  2. The class must contain a number property of type "long" that will represent the order in the list.
  3. Optionally create a sheet document for the class.  The sheet is different from ordinary sheet documents in that it must
    1. Be written directly in velocity syntax, without wrapping it in {{velocity}} tags.
    2. Declare a velocity macro #macro(renderObject $doc $obj $displayMode) that will be called to render each item in the list.
  4. Add a call the macro #dynamicList($className, $sheetDocument, $orderField in the document where you want the list.

Example

To create an application for managing a list of favourite animals create a class with the properties "animal" of type string and "order" of type long.

AnimalClass.png

Optionally create a sheet document on this form. Note the lack of {{velocity}} tags. The order property must be displayed in edit mode. It may be hidden, though. If wrapped in a container of class "DynamicList_OrderControl", the javascript will hide it.

#macro(renderObject $doc $obj $displayMode)
$doc.display('name', $displayMode, $obj)
(% class="DynamicList_OrderControl" %)(((
$doc.display('order', $displayMode, $obj)
)))
#end

Create a sheet document for the list:

{{include document="Code.DynamicListMacro" /}}

= My favourite animals =

{{velocity}}
#dynamicList('Sandbox.AnimalClass', 'Sandbox.AnimalSheet', 'order')
{{/velocity}}

A default sheet can be used by passing false instead of a document name for the sheet parameter.

Add a "SheetClass" object to the document to indicate that documents using it should be edited in "inline" mode.

Now use it by simply including the sheet document on a page:

{{include document="Sandbox.FavouritAnimalList" /}}

When editing the document in inline mode, an "Add" button should appear. Click on it to add new objects, and just input the desired values. The order can be rearranged by dragging the items.

AnimalReordering.png

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

The document Code.DynamicListMessages must be added as an internationalization bundle under "administrate wiki" "programming".

Get Connected