See Warlord implementation for details (by @tinhol )
Changes
Using new Action - ShowPivotAction
you can export data from components that extends ListComponent
class to the PivotTable
component.
Description
ShowPivotAction has several modes for export: all rows and selected rows. You don't have to select it, because it depends on selected rows.
All rows will be exported by default without confirmation dialog if you didn't select rows.
A confirmation dialog will be shown If you select some rows and click on a button with action:
The PivotTable
component will be shown in a new tab with editable = true
by default.
In the opened tab, PivotTable
has an extension that allows you to export pivot data to excel (if the current renderer is supported).
Note, if property has any type from following list:
- collection type;
- byte array
- uuid
or has system level annotation, or doesn't have security access for view, it will be ignored.
API
To create action, you should send component that extends ListComponent
class as a parameter. Also, you can send an action id otherwise default id will be used.
ShowPivotAction action = ShowPivotAction.create(table);
//or
ShowPivotAction action = ShowPivotAction.create(table, "actionId");
By default ShowPivotAction
send all properties that defined in the View
of CollectionDatasource
. If you want to send certain properties or exclude, you can use the following methods:
withIncludedProperties() // received List<String> of properties name;
withExcludedProperties() // received List<String> of properties name;
As ShowPivotAction
has a fluent API, you can use following code entry:
ShowPivotAction action = ShowPivotAction.create(table)
.withIncludedProperties(Arrays.asList("login", "name", "active", "group", "position"))
.withExcludedProperties(Arrays.asList("name", "position"));
The order of methods doesn't matter:
In the above example, the result of applied properties is: ("login", "active", "group")
If we change the order of invoked methods:
ShowPivotAction action = ShowPivotAction.create(table)
.withExcludedProperties(Arrays.asList("name", "position"))
.withIncludedProperties(Arrays.asList("login", "name", "active", "group", "position"));
The result of applied properties will be: ("login", "active", "group").
All incorrect properties are ignored.
To configure pivot table, you must use the following method:
withNativeJson() // received String json;
JSON structure for a non-editable pivot table:
{
"cols": ["localized property", "localized property"],
"rows": ["localized property"],
"editable": false,
"renderer": "heatmap",
"aggregation": {
"id": "d8fc3fdf-730d-c94f-a0c8-72a9ce3dcb3a",
"mode": "sumOverSum",
"properties": ["localized property", "localized property"]
}
}
JSON structure for editable pivot table:
{
"cols": ["localized property"],
"rows": ["localized property"],
"editable": true,
"renderers": {
"selectedRenderer": "barChart"
},
"autoSortUnusedProperties": true,
"aggregationProperties": ["localized property", "localized property"],
"aggregations": {
"selectedAggregation": "count",
"aggregations": [{
"id": "647780f0-c6d0-6ade-a63a-542b5c8cdbd5",
"mode": "count",
"caption": "Count"
}, {
"id": "c2663238-2654-67f0-2dec-add6962d867c",
"mode": "sumOverSum"
}]
}
}
For more information about configuration properties see https://github.com/nicolaskruchten/pivottable/wiki/Parameters
For QA
For non-persistent Entity (e.g. TipInfo)
Without and with view:
a) without "include" and "exclude" properties - should show all available properties
b) using withIncludedProperties()
- should show only included
c) using withExcludedProperties()
- should show available properties minus excluded
d) using both methods - excluded properties will be applied to included. If count of result properties is zero - all available properties will be shown.
For peristent Entity (e.g. User)
Without and with view
a - d) same steps
e) Check security for properties
f) Check uuid property
g) Check byte array property
h) Try to use in withIncludedProperties()
propertyPath (e.g. group.name)