enhancement
Similar to Excel, it should be possible to display a row in tables (including grids) that shows a calculated value for each column.
- The summary row is optional.
- The summary row can be configured to appear either directly below the header or above the footer.
- The summary row behaves similarly to the header or footer row (i.e., it scrolls horizontally with the columns but not vertically with the rows, so it is always visible).
- For each column, you can configure an algorithm that calculates the value to be displayed in the summary row for that column. If no algorithm is configured, no value is displayed in the summary row.
- The algorithm used to calculate the value for the summary row has access to the TableViewModel in order to perform the calculation.
Implementation
Table columns have been given the additional property `additionalHeaders`. This is a list of `HTMLFragmentProviders`, each of which renders an additional header row. Examples can be found in the [#Test|Test] section. The following was also implemented:
- HTMLFragmentProvider was introduced as a generalization of ControlProvider.
- The ` FragmentControlProvider` serves as an adapter for “legacy” APIs that continue to declare `ControlProvider `. It is a ` ControlProvider ` and has a property for an ` HTMLFragmentProvider`.
- TL 6: The following TL script functions were implemented:
- max, min, average, sum.
- Like all other TL-Script functions, these are documented in the com.top_logic.model.search/webapp/doc folder. In the demo, for example, this documentation is displayed in the model-based search on the second tab when you enter “sum” and press CTRL+SPACE.
- AdditionalHeaderControl and SimpleAdditionalHeaderControl were introduced as base classes for new additional columns.
- Using the shorthand <min/>, the following predefined ControlProviders can be used: min, max, average, median, sum, nullCount, nullPercentage.
- There are no additional rows in the footer. This is too complex and, according to current plans, will not be implemented until after a complete redesign of the frozen table technique. However, such a redesign is not yet foreseeable.
- The controls are called whenever a row is added to, modified, or removed from the table, and whenever the table is rewritten (more precisely: TableModelEvent.INVALIDATE).
- The controls receive an ` AdditionalHeaderControlModel` as their model. Through this, they retrieve the list of column values using `getValues() `.
- Specifically, this applies to the displayed rows:
- Filtered-out rows are NOT included.
- In trees, child elements of collapsed nodes are NOT included.
- Rows outside the viewport ARE included.
- Rows on other pages of the table ARE included.
- The rows are sorted exactly as they are currently displayed.
- In addition, controls using the class mentioned above have access to:
- getColumnIndex
- getColumnName
- getDisplayedRows
- getTableViewModel
- getRenderState
Code Migration
If a TableRenderer overrides the writeColumnHeader method: At the beginning of the method, you must also check whether this is an additional header column. In this case, you must call super. See, for example, the DemoTableRenderer:
#!patch
Index: branches/CWS/CWS_23681/com.top_logic.demo/src/com/top_logic/demo/table/DemoTableRenderer.java
===================================================================
--- branches/CWS/CWS_23681/com.top_logic.demo/src/com/top_logic/demo/table/DemoTableRenderer.java (revision 281102)
+++ branches/CWS/CWS_23681/com.top_logic.demo/src/com/top_logic/demo/table/DemoTableRenderer.java (revision 281391)
@@ -19,19 +19,19 @@
*/
public class DemoTableRenderer extends DefaultTableRenderer {
public DemoTableRenderer(InstantiationContext context, Config config) throws ConfigurationException {
super(context, config);
}
@Override
public void writeColumnHeader(DisplayContext context, TagWriter out, RenderState state, int rowNumber, int column)
throws IOException {
- if (rowNumber == 0) {
+ if ((rowNumber == 0) || isAdditionalHeader(rowNumber)) {
super.writeColumnHeader(context, out, state, rowNumber, column);
} else {
out.writeText("Header Row: " + rowNumber + " Col: " + column);
}
}
}
Test
There are examples of additional headers in three views in the demo:
- "Tables > Frozen" contains examples of multiple headers defined via ControlProvider.
- In all columns except Name and the selection column, there should be two additional headers.
- In "Float," the maximum and minimum values are displayed.
- In "Float (no special configuration)," the average and the sum are displayed.
- In all other columns, the number of null values and the percentage of null values are displayed.
- TL 6: "Tables > Tree Grid" contains examples of headers defined using TL-Script:
- In all columns except the "Name" and "Selection" columns, there should be two additional headers.
- In "Float," the maximum and minimum values are displayed.
- In "Float (no special configuration)," the average and the sum are displayed.
- In all other columns, the number of null values and the percentage of null values are displayed.
- "Structures > Structures > Type Demo": If an "A" is displayed, the "priorityTable" table contains an additional header. In all columns except "Name" and the selection column, the number of null values should be displayed. This table serves as an example to show that additional headers are also displayed correctly in the form.