Enabling Pivot Table Views
This describes the process of enabling and using the Webix Pivot Table control on the Klevr Portal.
Feature Overview
This describes the process of enabling and using the Webix Pivot Table control on the Klevr Portal.
Assumptions
- You have read this entire document
Dependencies
The following are dependencies for this feature:
None identified
Design Details
The design includes a few additional properties on a subgrid control in Umbraco, allowing you to select to render a list as a pivot control and specifying its parameters. The configuration of the control is left open and needs to be populated with the correct JSON for it to work. See further details below.
Requirements for the control is to be able to download the pivot table if various formats, including Excel and PDF. There's also a requirement to save and share custom pivot configuration, and this is achieved through the generation of a hyperlink that contains the users configration changes. This can then be bookmarked or shared with other colleagues who have access to the same page. The data loaded in the pivot control follows the standard klevr portal security model, so different users may see different data.
Security Considerations
- Access to the data used in the pivot control follows the same pattern as for a list control. The table permission filters will be applied to to the query, and therefore may show different records to different logged in users.
Process
In order for you to be able to use the pivot control you need to perform the following steps:
Use Dynamics Form 2.0 or Dynamics List 2.0 to get the new pivot features. These pages allow you to combine normal lists or pivot tables in a tabbed view control.
Create a subgrid on the page as per usual, specifying names, labels, fetchxml. If you specify klevr_names for attributes, then these will be used in the configuration of the pivot, so perhaps leave these as the standard schema names so that you are working with schema names in the pivot configuration as well. Within the pivot configuration you can specify friendly names for the fields.
Specify list buttons.
For the buttons, you can invoke the following built in functions:
| Action | Recomended icon | Javascript function |
|---|---|---|
| Download as PDF | pi pi-file-pdf | this.ToPDF |
| Download as Excel | pi pi-file-excel | this.ToExcel |
| Download as image (png) | pi pi-image | this.ToPNG |
| Copy user configuration to clipboard | pi pi-copy | this.ToLink(true) or this.ToLink(false) specifying true will both copy the url to the clipboard and refresh the page to include the config parameter so that it can be bookmarked. Specifying false will only copy the url. |
Specify the group name on the subgrid if you want this to appear as a tab alongside other lists. Specify the same group name for the other lists you want in the tabbed view. The grouped lists need to be adjacent to each other in the umbraco configuration too. The group name can be anything, it is not displayed. You could use numbers as well. Leave the group name blank to render the all the specified subgrids below each other.
Specify the pivot configuration. There are a multitude of settings available, but at a minimum you need to specify a structure object, containing the rows, columns and values to display by default. It is also recomended to specify the fields, in order to give them friendly names. The names of the fields in the row, column filter and value arrays must match the names given in the fetchxml. If you did not specify klevr_names, then you use the schema names here, otherwise you use the klevr_names assigned to the columns. Date fields in your dataset automatically get additional fields added, suffixed with the different parts: _year, _month, _day, _weekday, _hours, _minutes, _seconds. These can be used in your pivot configuration too, e.g. if you want to group by the created on year, you would use 'createdon_year'. See
- https://docs.webix.com/api__refs__ui.pivot_props.html for a full list fo properties
- https://docs.webix.com/api__ui.pivot_structure_config.html for detailed use of the structure section.
Here is an example of a basic configuration. Note you can set the startup view mode to "table", "tree" or "graph". Also, the field names uses the names from your fetchxml (schema names if no names are specified):
{
structure: {
rows: ["klevr_name"],
columns: ["createdon"],
values: [{ name: "klevr_number", operation: ["min", "sum"] }],
},
mode: "tree",
height:400
}
There are also options for filters, group by, total operations to name a few.
Default operations include ("sum", "min", "max", "avg", "wavg", "count", "any"), and you can also specify custom operations with your own javascript functions for calculations.
To format the numbers, you can specify a fomatting function. The snippet below will format it according to the en-US locale, which will add a comma as thousands separator, and full stop for decimals, up to 2 places. You can replace it with your own custom javascript function if you want more control, or concatenate it with for instance a "$" symbol for currency fields:
"values":[{"name":"klevr_amount","operation":"sum", format: (v) => v.toLocaleString("en-US") }],
Example of adding a $:
"values":[{"name":"klevr_amount","operation":"sum", format: (v) => "$" + v.toLocaleString("en-US") }],
Specifying fields: In order to allocate friendly names to fields, you have to specify a list of fields in your configuration, for example:
{
....
height: 400,
fields: [
{id: "klevr_name", value: "Name", type: "text" },
{id: "klevr_amount", value: "Amount", type: "number" },
{id: "klevr_customer", value: "Customer", type: "text" }
],
The ID of the field is the name from the fetch, typically the schema name if you did not specify a klevr_name. The Value of the field is the display name shown to the end user. Types could be text, number, date. You can specify predicates (see webix documentation) as well as a "prepare" function to format the values. For instance, if you are using a date field, you should specify the following fields:
{
... //as above
fields: [
{id: "klevr_transactiondate", value: "Year-Month", type: "text", prepare: v => v.getFullYear() + "-" + v.getMonth() },
{id: "klevr_transactiondate_year", value: "Date year", type: "number" },
{id: "klevr_transactiondate_month", value: "Date month", type: "text" },
{id: "klevr_transactiondate_day", value: "Date day", type: "number" },
{id: "klevr_transactiondate_weekday", value: "Date weekday", type: "text" },
//optionally specify hours, minutes
]
}
In this example, my date column is formatted as year - month, and I have assigned friendly names to the other generated date fields.
When you add date fields to the column section of your pivot, they will automatically sort descending, except for month and weekday, which will sort Jan - Dec and Sunday to Saturday respectively.
📎 References
Last updated on