General Actions:
| Displays a dynamic, filterable and sortable table of data |
| Type | Macro (Velocity) |
| Developed by | |
| License | GNU Lesser General Public License 2.1 |
| Bundled With | XWiki Enterprise, XWiki Enterprise Manager |
| Compatibility | XWiki Enterprise >= 1.9M2 |
Table of contents
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.).
The signature of the macro is the following :
Each parameter allows to control the output generated by the macro. Namely:
The following sections give more details and examples about the last three parameters, $options, $columns and $columnsProperties.
| Option name | Description | Default value | Since |
|---|---|---|---|
| className | The 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 wiki. This parameter can be ignored by a custom data source if either the resultPage or the url parameters are used. | None | |
| resultPage | The 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 the url parameter is used. | None | |
| url | This is similar to resultPage, except that it accepts an URL instead of the full name of the page to obtain results from. This allows for example to add extra query parameters. | None | |
| selectedColumn | The 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 | |
| defaultOrder | The default order to sort on the selected column. Accepted values are asc and desc | asc | |
| rowCount | The maximum number of rows to display in one page of the table. | 15 | |
| maxPages | The 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 | |
| translationPrefix | A 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 | |
| tagCloud | Display 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 selection | false | |
| callback | An 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 | |
| extraParams | Used to add extra parameters to the Ajax request for the resultPage which generates the JSON data. Must start with an "&". Example: "extraParams" : "&page=MySpace.PageName". You can also use this option to retrieve all the documents from a certain space ("extraParams" : "&space=${doc.space}"), from a certain parent ("extraParams" : "&parent=${doc.parent}") or all the objects that have a specific value for a property ("extraParams" : "&yourProperty=yourValue" - note that in this particular case, yourProperty has to be declared in the $columns array) | None | |
| topFilters | HTML fragment that will be placed in a "top filter" area in the same fashion as the Tag Cloud filter. All filters elements (input, select) in this fragment will be automatically used as filters for the livetable. | None | 2.3 RC 1 |
| pageSize | Display a selection box to allow users to change the number of rows displayed per page in the table | true | 2.4 M1 |
| pageSizeBounds | Defines the page sizes available in the selection box that allows users to change the number of rows displayed per page in the table. This should be a valid initialization of a Javascript array of 3 integer values: the minimum page size, the maximum page size, and the steps between proposed page sizes. The default value propose a selection between 10 and 100 with a step of 10, which means 10, 20, 30, ..., 90 and 100 in the proposed list of sizes. | [10,100,10] | 2.4 M1 |
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.
| Name | Description |
|---|---|
| doc.name | The name of the document (for example, WebHome, in Sandbox.WebHome). |
| doc.title | The title of the document. |
| doc.space | The space of the document (for example, Sandbox, in Sandbox.WebHome). |
| doc.fullName | The full name of the document (for example Sandbox.WebHome). |
| doc.creationDate | The date at which the document was created. |
| doc.creator | The username of the user that created the document. |
| doc.author | The username of the last author of the document. |
| doc.date | The 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). |
| _images | A special column to display all images attached to the retrieved document. |
| _attachments | A special column to display links to all attachments of the retrieved document. |
| _actions | A special column to display a list of actions that can be performed by administrators on the matched documents. |
| _avatar | A special column to display the user avatar. Works only for a table bound to the XWiki.XWikiUsers XWiki class. |
| Name | Descriptions | Default value | Since |
|---|---|---|---|
| displayName | The name to display as a column header for this column (wins over the translationPrefix table option) (Note: available starting with XE 2.3) | None | 2.3 |
| filterable | Should the column present a filter on its header? | true1 | |
| sortable | Should the column be available as a sort key? | true | |
| type | For 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) | |
| size | The size of the filter field. CSS might override this value to make the field 100%. | None | |
| link | The 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) | |
| html | Should the returned value be treated as HTML and injected as is in the row ? | false | |
| headerClass | The name of an optional CSS class to add to the column HTML table column header. | None | 2.3 RC 1 |
| class | Specifies 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 |
The url option can also be used to generate the user directory:
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.
The content of MySpace.ListOrganizationJSON (using syntax 2.0):
The livetable rows can also be created using a Javascript callback function. For example, the Attachments tab on Document Index:
The callback function created the columns for each row using the JSON generated by the url parameter:
Here's a minimal working example, displaying two fields ("user" and "message").
Page using the livetable:
Space.MyJSON Page:
Note that in order to support paging, filtering and sorting you'll need to handle the following URL parameters:
For example here's the request sent if you typed the letter t in the message column:
Starting with XWiki Enterprise 4.0 you can modify the default JSON before it is sent to the client side to feed the live table. Space.MyJSON page could look like this:
Create a translation page that you register as a Document Resource Bundle and use the translationPrefix value as the key prefix. For example if you've used "translationPrefix" : "xwikiorg.extensions." then use:
If you don't want to display any text use:
Create a translation page that you register as a Document Resource Bundle and use the following translation keys as the key prefix for the _actions column:
It's not possible to filter on doc.title.