Klevr Product Documentation logo

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

  1. 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

  1. 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:

1
Use a page type that supports pivots

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.

2
Create the subgrid

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.

3
Specify list buttons

Specify list buttons.

For a standard subgrid, listbuttons are rendered per line, but when you choose to render the list as a pivot, the list buttons are rendered as single overall buttons to the pivot control.
4
Configure the button actions

For the buttons, you can invoke the following built in functions:

ActionRecomended iconJavascript function
Download as PDFpi pi-file-pdfthis.ToPDF
Download as Excelpi pi-file-excelthis.ToExcel
Download as image (png)pi pi-imagethis.ToPNG
Copy user configuration to clipboardpi pi-copythis.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.
5
Group tabs (optional)

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.

6
Specify the pivot configuration

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

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
]
}
Comments and ... are not valid in JSON, the comments above are for clarity and needs to be removed if you are copying and pasting. the ... is inserted as a placeholder for the structure and other definitions you may have.

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