Live Table Macro

This is a Velocity macro, bundled with all the XWiki products by default.
Macro developed by the XWiki Development Team.
This macro cannot currently be downloaded separately.

LiveTable Macro

Warning: This macro is available in XE 1.9M2 and later versions only

The most common use case of the livetable macro is displaying a table of documents that contains an XWiki Object of a certain class. This is a powerful way for in-wiki applications developers to offer a mining interface on their application data (for example Contacts in a CRM/Contact manager, Bills in a Billing application, etc.).

Usage

The signature of the macro is the following :

#livetable($id $columns $columnsProperties $options)

Each parameter allows to control the output generated by the macro. Namely:

  • $id is a string identifier that allows to distinguish this table from others. This permits to have several tables on the same page. This id is used in the generated HTML as prefix for some elements' ids.
  • $columns is an array that holds the ordered list of columns to display in the table.
  • $columnsProperties is a hash of properties (options) to customize the behavior of each of the columns
  • $options is a hash with general options (as opposed to columns options) for the table.
The following sections give more details and examples about the last three parameters, $options, $columns and $columnsProperties.

Parameter $options

Example

#set($myTableOptions = { 
   "className":"XWiki.XWikiUsers",
   "translationPrefix" : "xe.index.users.",
   "tagCloud" : true,
   "rowCount": 10
})

All accepted values

Option nameDescriptionDefault value
classNameThe full name of the XWiki page holding the class definition for the type of data to display in the table. For example: XWiki.XWikiUsers to display pages with objects of type users. If no className is given (nor any of the resultPage or url options - see below), the table will display all pages of the wikiNone
resultPageThe full name of the page to use as a JSON data provider for the table. This option allows to use a different data source than the default one (XWiki.LiveTableResults) for specific needs not handled by LiveTableResults (for example: complex cross-classes queries, external data retrieved with a groovy script, etc.). This parameter will be ignored if a className parameter is present.None
urlThis is similar to resultPage, except that it accepts a URL instead of the full name of the page to obtain results from. This allows for example to add extra query parameters. This parameter will be ignored if at least one of the optionsclassName or resultPage is given.None
selectedColumnThe name of the column on which to sort the live table by default. If this option is absent, the first sortable column met in the $columns array will be used.None
defaultOrderThe default order to sort on the selected column. Accepted values are asc and descasc
rowCountThe maximum number of rows to display in one page of the table.15
maxPagesThe maximum number of pages links to display in the pagination UI (Not including the links to the first and last pages that will always be displayed).10
translationPrefixA string to prefix table translation keys with (for names of columns for example) in order to have different display messages (translated strings) for different tables.None
tagCloudDisplay a tag cloud filter and display interface to allow users to see entries matching particular tags and to see which tags match the current filter selectionfalse
callbackAn advanced option to pass the name of a JavaScript method as custom handler of matched rows, leaving the responsibility of the DOM construction of the row entry, and its injection in the table to this method. This option should be used when complex manipulations are needed to construct row entries, which is not possible to do using the default handler. You can see an usage example of this option in the "All Attachments" UI in the XWiki Enterprise document index.None
extraParamsUsed to add extra parameters to the Ajax request for the resultPage which generates the JSON data. Example: "extraParams" : "page=MySpace.PageName".None

Parameter $columns

This parameter allows to define the columns of the Live Table. There are 3 major types of columns a table can declare: document columns, which will be displaying (and filtering on) metadata on the document (such as its author, date of last modification, etc.) object properties columns, for the case the table is bound to an XWiki Class, and special columns, for columns which are not handled by the first two types, such as the list of attachments of a document, the actions that can be performed. The table below in the example summarizes all the possible values that can be passed to the $columns array.

Example

#set($myColumns = ["_avatar", "first_name", "last_name", "email", "doc.creationDate", "_actions"])

All accepted values

NameDescription
doc.nameThe name of the document (for example, WebHome, in Sandbox.WebHome).
doc.titleThe title of the document.
doc.spaceThe space of the document (for example, Sandbox, in Sandbox.WebHome).
doc.fullNameThe full name of the document (for example Sandbox.WebHome).
doc.creationDateThe date at which the document was created.
doc.creatorThe username of the user that created the document.
doc.authorThe username of the last author of the document.
doc.dateThe date at which the document has been last modified.
${propertyName}Any property of an XWiki Class the table is bound to. (See the className parameter of the $option argument for more information on how to bind a table to a XWiki Class).
_imagesA special column to display all images attached to the retrieved document.
_attachmentsA special column to display links to all attachments of the retrieved document.
_actionsA special column to display a list of actions that can be performed by administrators on the matched documents.
_avatarA special column to display the user avatar. Works only for a table bound to the XWiki.XWikiUsers XWiki class.

Parameter $columnsProperties

Example

#set($columnsProperties = {
   "_avatar" : { "type" : "none", "link" : "none", "html" : "true", "sortable":false },
   "first_name" : { "type" : "text" , "size" : 20, "link" : "view"},
   "last_name" : { "type" : "text", "link" : "view"},
   "email" : { "type" : "text" }
})

All accepted values

  • Document and object fields options:
NameDescriptionsDefault value
displayNameThe name to display as a column header for this column (wins over the translationPrefix table option) (Note: available starting with XE 2.3)None
filterableShould the column present a filter on its header?true
sortableShould the column be available as a sort key?true
typeFor filterable columns, the type of filter for the column. Also allows to hide a column. Possible values in hidden, text, list, number.None (no type)
sizeThe size of the filter field. CSS might override this value to make the field 100%.None
linkThe type of link to use for the field value, in view, field, none. "view" links to the page corresponding to the row. "field" links to the page corresponding to the field value (for DBListClass). "hidden" hides the column. "none" has not link.None (no link)
htmlShould the returned value be treated as HTML and injected as is in the row ?false
classSpecifies the full name of the XWiki class for the type of data to display in the table. Used by the filtering options in the live table header, when the $options hash has resultPage key instead of className.None

Examples

The user directory

#set($columns = ["_avatar", "first_name", "last_name", "email", "doc.creationDate", "_actions"])
#set($columnsProperties = {
    "_avatar" : { "type" : "none", "link" : "none", "html" : "true", "sortable":false },
    "first_name" : { "type" : "text" , "size" : 20, "link" : "view"},
    "last_name" : { "type" : "text", "link" : "view"},
    "email" : { "type" : "text" }
})
#set($options = { 
   "className":"XWiki.XWikiUsers",
   "translationPrefix" : "xe.index.users.",
   "tagCloud" : true,
   "rowCount": 10
})
#livetable("userdirectory" $columns $columnsProperties $options)

Demo (Video)

Filter organizations by domain

The organization class in the example below has two properties: an org_name of type String and an org_domain of type StaticList. The organization domain can have values like Software or Hardware , which will be used in the live table as filter options.

#set($columns = ["org_name", "org_domain"])
#set($columnsProperties = {
    "org_name" : { "type" : "text" , "size" : 20, "link" : "view"},
    "org_domain" : { "type" : "list", "class": "MySpace.OrganizationClass"}
})

#set($options = { "resultPage":"MySpace.ListOrganizationJSON", "translationPrefix" : "", "rowCount": 10 }) #livetable("organization_directory" $columns $columnsProperties $options)

The content of MySpace.ListOrganizationJSON (using syntax 2.0):

{{include document="XWiki.LiveTableResultsMacros" /}}
{{velocity}}
#gridresultwithfilter("MySpace.OrganizationClass" $request.collist.split(",") "" " and doc.name<>'OrganizationSheet' and doc.name<>'OrganizationTemplate'")
{{/velocity}}

Advanced

For more details on how LiveTable works, check the Live Table section in the Dev Guide.

Tags:
Created by Asiri Rathnayake on 2009/09/10 08:40
Last modified by Oana Tabaranu on 2010/03/17 15:29

This wiki is licensed under a Creative Commons license
2.2.1.27354