Livetable Macro
Displays a dynamic, filterable and sortable table of data |
Type | Doc (Velocity Macro) |
Category | |
Developed by | Unknown |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Compatibility | XWiki Enterprise >= 1.9M2 |
Table of contents
Description
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 :
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
"className":"XWiki.XWikiUsers",
"translationPrefix" : "xe.index.users.",
"tagCloud" : true,
"rowCount": 10
})
All accepted values
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 | |
selectedTags | The list of tags that should be selected initially in the tag cloud. You can still select different tags from the tag cloud after the live table loads. | [] | 5.4RC1 |
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. | None | |
extraParams | Used to add extra parameters to the Ajax request for the resultPage which generates the JSON data. Must start with an "&" (If you add multiple settings when using this option they have to be separated with an "&"). You should also use the EscapeTool to URL-encode any special character in your parameter values (e.g. the space name since that space can contain any character). For example: 'extraParams' : "&space=$escapetool.url('ComitĂȘ')". The parameters allowed depend on the implementation of the resultPage. For the default resultsPage (i.e. XWiki.LiveTableResults) here's what's supported:
| 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 |
queryFilters | Optionally specifies a comma-separated list of already registered Query filter names to apply. Pass the empty string if you don't want any query filters to be applied. If not specified, the default query filters are applied. Note: This is not the place where you would add "WHERE" clauses, but it`s for the actual name of existing query filters (e.g. "unique", "hidden", etc.). If extra "WHERE" clauses is what you are looking for, then you should use the extraParams option instead. | currentlanguage, hidden | 6.0 M1 |
outputOnlyHtml | If set to true, it ensures that the output of the livetable macro is only HTML markup, without the syntax specific wrappers ({{html}}{{/html}} macro wrapper for syntax 2.0 or {pre}{/pre} wrappers for syntax 1.0). It is most useful when using the livetable macro inside filesystem velocity templates. | false | 6.3 M2 |
description | When provided, the value is used for the caption of the Livetable. | the empty string, option | 6.0 M1 |
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
All accepted values
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.location | The location of the document (for example, Main / Sandbox, in Sandbox.WebHome). Note that the returned value of this column will automatically be treated as html. |
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. |
doc.objectCount | The number of objects of the type indicated by the className parameter found on the page. This column is useful only if you expect your pages to have multiple objects of the className type. If that is the case then you should probably also use the unique query filter (see the queryFilters parameter). |
${propertyName} | Any property of an XWiki Class the table is bound to, or from any secondary classes. (See the className and extraParams from the $option argument for more information on how to bind a table to an XWiki Class and how to view propertis from other classes). |
_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 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. |
Parameter $columnsProperties
Example
"_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", "html" : "true" }
})
All accepted values
- Document and object fields options:
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? true12 sortable Should the column be available as a sort key? true type For filterable columns, the type of filter for the column. Valid values are: - hidden (allows to hide a column)
- text
- list
- number
- boolean
- multilist (allows the user to filter on multiple values of a list)
- date
- suggest (supported by Database List, List of Users and List of Groups property types).
None (no type) match (6.3M1+) For filterable columns, specifies how the filter value should be matched against the stored value. Possible values are: exact, partial, prefix. The default live table results page is currently supporting this option for the following property types: StringProperty, LargeStringProperty and DBStringListProperty. Custom live table results pages might not provide this option. None (depends on the column data 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 this column. The following options are available, in order:
- auto: link to the URL provided by the <columnName>_url row property from the JSON results, if present, otherwise fall back on the doc_url property
- field: same as auto but without the fallback; this can be used for instance with Database List properties in order to link the column value to the corresponding XWiki document
- editor: link to edit the corresponding object property (requires LiveTable Property Editor)
- <property>: link to the URL provided by the doc_<property>_url row property from the JSON results, if present, otherwise fall back on the doc_url property. The following properties are currently supported by the default live table results JSON: author, space, wiki, XWiki 9.1+ edit, copy, delete, rename, rights. You can of course use other properties as long as you add doc_<property>_url to your custom JSON results.
Note that you need to set the doc_viewable row property to true in order for these values to be taken into account. Leave this empty or don't specify it at all if you don't want to link the column value.
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 or when the column comes from a different object than the one pointed to by className . None - _actions options:
Name Descriptions Default value Since actions The list of actions to display on this column. An action can be specified as a string (the action name) or as a map with more advanced action properties. The following list of actions are supported by the default live table results page: view, edit, copy, rename, delete, rights. The action URL for each row is specified by the doc_actionName_url field in the live table JSON. E.g.: 'actions': [
'edit', 'delete',
{
'id': 'custom',
'label': 'Custom',
'icon': 'eye',
'async': true,
'callback': 'callSomeJavaScriptFunction()'
}, {
...
}
][]
Examples
The user directory
#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", "html" : "true"}
})
#set($options = {
"className":"XWiki.XWikiUsers",
"translationPrefix" : "xe.userdirectory.",
"tagCloud" : true,
"rowCount": 10
})
#livetable("userdirectory" $columns $columnsProperties $options)
The url option can also be used to generate the user directory:
"url" : "$xwiki.getURL('XWiki.LiveTableResults', 'get', 'outputSyntax=plain&transprefix=xe.index.users.&classname=XWiki.XWikiUsers&collist=_avatar,first_name,last_name,email,doc.creationDate')",
"translationPrefix" : "xe.userdirectory.",
"tagCloud" : true,
"rowCount": 10
})
Demo (Video)
- ^ note that filtering on doc.title does not work as expected and was disabled before XWiki 10.9
- ^ Before 9.5RC1 only list, text, number are filterable. Since 9.5RC1, date type columns can also be filtered. If you are on an older version, you can try out the extension for a date filter.