Skip to content

Commit e229270

Browse files
feat(ui5): Add table best practices skill (#78)
Offers table-specific guidelines as a skill containing core rules, the control selection matrix, common errors, and container structures. Per-control detail lives in eight reference files loaded on demand: sap-m-table, grid-table, tree-table, smart-table, mdc-table, drag-and-drop, personalization, cell-templates. JIRA: CPOUIFTEAMB-2652 JIRA: CPOUIFTEAMB-2584 Gerrit: 7245230
1 parent 5d07411 commit e229270

10 files changed

Lines changed: 702 additions & 0 deletions

File tree

plugins/ui5/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ Guidelines and debugging workflow for OPA5 integration tests:
5151
- **Page object organization** - Placement of actions and assertions across views
5252
- **App teardown** - Cleanup patterns in OPA5 journey tests
5353

54+
#### ui5-best-practices-tables
55+
56+
Authoritative development guidelines for all UI5 table controls (SAPUI5 1.136+ LTS):
57+
58+
- **Control selection matrix** - When to use `sap.m.Table`, `sap.ui.table.Table`, `TreeTable`, `SmartTable`, or `sap.ui.mdc.Table`
59+
- **Core rules and prohibitions** - Mandatory patterns and common mistakes to avoid
60+
- **Common errors** - Symptom/cause/fix table for the most frequent table bugs
61+
- **Container structures** - Valid and invalid layout containers for tables
62+
- **Per-control API guidance** - Binding syntax, key properties, minimal examples, and events for each table type
63+
- **Drag & drop** - Correct `DragDropInfo` and `DragInfo`/`DropInfo` configuration
64+
- **Personalization** - `sap.m.p13n.Engine` integration
65+
- **Cell templates & alignment** - Type-based alignment and model type namespace rules
66+
5467
---
5568

5669
## Installation
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
name: ui5-best-practices-tables
3+
description: |
4+
UI5 table best practices and authoritative development guidelines. Use when the user asks to "create a table", "add a table", "which table should I use", "implement sap.m.Table", "implement sap.ui.table", "GridTable", "ResponsiveTable", "TreeTable", "SmartTable", "MDC table", "sap.ui.mdc.Table", "sap.ui.comp.smarttable", "table not showing data", "table binding", "table selection", "drag and drop table", "table personalization", "copy paste table", "table export", "table sticky header", "table growing", "table pop-in", "table performance", "table accessibility", "table items binding", or is writing any UI5 freestyle application that includes a table control. Covers: control selection matrix, mandatory rules, common error patterns, and per-control API guidance for sap.m.Table, sap.ui.table.Table, sap.ui.table.TreeTable, sap.ui.comp.smarttable.SmartTable, and sap.ui.mdc.Table.
5+
6+
Keywords: sap.m.Table, sap.ui.table, GridTable, ResponsiveTable, TreeTable, SmartTable, sap.ui.mdc.Table, table binding, rows aggregation, items aggregation, rowMode, growing, sticky, personalization, drag and drop, DragDropInfo, p13n.Engine, OData V4, OData V2, cell templates, ariaLabelledBy
7+
---
8+
9+
# UI5 Table Best Practices
10+
11+
Apply these guidelines whenever generating, reviewing, or troubleshooting UI5 table code in freestyle applications.
12+
13+
**UI5 version baseline:** SAPUI5 1.136+ LTS. All features mentioned are available from this version unless noted.
14+
15+
## When to load each reference
16+
17+
| Trigger | Load |
18+
|---|---|
19+
| Working on or planning a `sap.m.Table` (ResponsiveTable) | [`references/sap-m-table.md`](references/sap-m-table.md) |
20+
| Working on or planning a `sap.ui.table.Table` (GridTable) | [`references/grid-table.md`](references/grid-table.md) |
21+
| Working on or planning a `sap.ui.table.TreeTable` | [`references/tree-table.md`](references/tree-table.md) |
22+
| Working on or planning a `sap.ui.comp.smarttable.SmartTable` | [`references/smart-table.md`](references/smart-table.md) |
23+
| Working on or planning a `sap.ui.mdc.Table` | [`references/mdc-table.md`](references/mdc-table.md) |
24+
| Adding drag-and-drop to any table | [`references/drag-and-drop.md`](references/drag-and-drop.md) |
25+
| Adding column personalization | [`references/personalization.md`](references/personalization.md) |
26+
| Choosing cell templates, alignment, or data type binding | [`references/cell-templates.md`](references/cell-templates.md) |
27+
28+
Load before producing any output. Do not work from memory.
29+
30+
---
31+
32+
## Core Rules
33+
34+
### Mandatory
35+
36+
- Choose the table type using the [Selection Matrix](#selection-matrix) before writing any code.
37+
- Use the `rows` aggregation for `sap.ui.table.*` and `items` for `sap.m.Table`. Never swap them.
38+
- Use `sap.m.p13n.Engine` for personalization. Never build custom personalization dialogs.
39+
- Set `ariaLabelledBy` on every table, referencing the table title control.
40+
- Align cell content by data type: numbers and dates right (`hAlign="End"`), text and links left.
41+
- Use appropriate cell templates: `sap.m.Text` for display, `sap.m.ObjectNumber` for numbers, `sap.m.Link` for navigation.
42+
- Request `$count=true` from the back end for `sap.ui.table.*` when a total count is required.
43+
- Use the `rowMode` aggregation (not the deprecated `visibleRowCountMode` property) for `sap.ui.table.*` (UI5 1.119+).
44+
45+
### Prohibitions
46+
47+
- Do not use global variables. Use `sap.ui.define` AMD modules or ES6 imports.
48+
- Do not enable text wrapping in `sap.ui.table.*` cells — it breaks virtualization.
49+
- Do not assume `sap.ui.export.Spreadsheet` is available. Detect the library before use.
50+
- Do not use `sap.ui.table.Table` for mobile-first scenarios. Use `sap.m.Table`.
51+
- Do not use `sap.m.Table` for datasets with 1000+ rows that require virtualization.
52+
- Do not place multiple interactive elements in one `sap.ui.table.Table` cell.
53+
- Do not return enum objects from formatters. Return string literals or primitive values.
54+
- Do not use formatters for `ColumnListItem` `highlight`. Use direct data binding.
55+
- Do not access models without checking availability — causes "Cannot read properties of undefined".
56+
- Do not mix type namespaces: never use `sap.ui.model.odata.type.*` with a JSON model, or `sap.ui.model.type.*` with OData.
57+
58+
### OData V4 policy
59+
60+
Prefer SAP Fiori elements building blocks over freestyle tables for OData V4. Use `sap.ui.mdc.Table` only when Fiori elements is out of scope.
61+
62+
---
63+
64+
## Selection Matrix
65+
66+
| Table type | Use when | Do not use when |
67+
|---|---|---|
68+
| `sap.m.Table` | Mobile/responsive, pop-in behavior, JSON models, fewer than 100 rows | 1000+ rows, virtualization required, desktop-only, cell selection needed |
69+
| `sap.ui.table.Table` | Desktop, 1000+ rows, virtualization, fixed columns, dense data | Mobile-first, pop-in required, text wrapping, small datasets |
70+
| `sap.ui.table.TreeTable` | Hierarchical data, expand/collapse, parent-child relationships | Flat data, mobile-first, grouping (not hierarchy) |
71+
| `SmartTable` | OData V2, annotations, automatic columns, smart filtering | JSON-only, precise control required, OData V4 |
72+
| `sap.ui.mdc.Table` | OData V4 freestyle (when Fiori elements is ruled out), delegate pattern | JSON-only, simple apps, OData V2 |
73+
74+
### Dataset size guide
75+
76+
| Rows | Recommended table | Strategy |
77+
|---|---|---|
78+
| < 100 | `sap.m.Table` | Simple binding, `growing` optional |
79+
| 100–1000 | `sap.ui.table.Table` | Virtualization, `threshold=100` |
80+
| 1000+ | `sap.ui.table.Table` | Virtualization, `threshold=100–500`, `$count=true` when needed |
81+
82+
---
83+
84+
## Common Errors
85+
86+
| Symptom | Cause | Fix |
87+
|---|---|---|
88+
| No data displayed | Incorrect binding path or missing model | Verify `bindRows`/`bindItems` path and model attachment. |
89+
| Rows not scrolling (`sap.ui.table.*`) | Count not requested | Set `$count=true` for OData when a total count is required. |
90+
| Selection not working (`sap.ui.table.*`) | Plugin conflict | Do not call the table selection API when a selection plugin is applied; use the plugin API instead. |
91+
| Text wrapping issues | Wrapping enabled in `sap.ui.table.*` | Use fixed-height content or switch to `sap.m.Table`. |
92+
| Copy/paste not working | Plugin not attached or wrong namespace | Attach the correct plugin (see Drag & Drop section). |
93+
| Personalization not persisting | Engine not configured | Verify `sap.m.p13n.Engine` registration. |
94+
| `CopyProvider` error | `extractData` not defined | Implement `extractData` on the plugin. |
95+
| Table not visible | Invalid container structure | Use a valid container (see Container Structures). |
96+
| OData types on JSON model | Wrong type namespace | Match the type namespace to the model: `sap.ui.model.type.*` for JSON, `sap.ui.model.odata.type.*` for OData V2, `sap.ui.model.odata.v4.type.*` for OData V4. |
97+
| Excel export fails silently | Library not loaded or invalid `extractData` | Detect the library, return a 2D array from `extractData`, ensure `dataSource` binding. |
98+
| "No Data Available" | Model not set before binding | Set the model in `Component.init()` before router initialization. |
99+
100+
---
101+
102+
## Container Structures
103+
104+
### Valid
105+
106+
| Structure | Use case |
107+
|---|---|
108+
| `View > Page > content > Table` | Standard page |
109+
| `View > Page > content > Panel > Table` | Grouped content |
110+
| `View > Page > content > IconTabBar > items > IconTabFilter > Table` | Tabs |
111+
| `View > SplitApp > detailPages > Page > Table` | Master-detail |
112+
| `View > Dialog > content > Table` | Modal |
113+
| `View > Table` | Standalone |
114+
115+
### Invalid (and why)
116+
117+
| Structure | Issue |
118+
|---|---|
119+
| `Page > content > VBox > Table` | `VBox` needs explicit height — table becomes invisible |
120+
| `Page > VBox > Table` | `VBox` not in `content` — table not rendered |
121+
| `Page > content > FlexBox > Table` | Sizing conflict — table collapses |
122+
| `Page > content > ScrollContainer > Table` | Double scrolling — virtualization breaks |
123+
124+
---
125+
126+
## Performance & Accessibility
127+
128+
### Anti-patterns to avoid
129+
130+
- Handcrafted personalization dialogs (use `sap.m.p13n.Engine`).
131+
- Text wrapping in `sap.ui.table.Table` cells.
132+
- Multiple interactive elements in one GridTable cell.
133+
- Mixing OData V2 `SmartTable` with V4 services.
134+
- Deep nesting in cell templates.
135+
- Fixed `threshold` without load testing.
136+
- Unconditional `$count=true` (request count only when needed).
137+
138+
### Accessibility checklist
139+
140+
- Set `ariaLabelledBy` on every table, referencing the visible title.
141+
- Use `sap.m.Text` (not raw text nodes) as cell templates.
142+
- For `sap.ui.table.Table`: test keyboard navigation (Tab, arrow keys, Space/Enter for selection).
143+
- Verify that the personalization dialog is keyboard-operable.
144+
- Test with a screen reader (NVDA/JAWS on Windows, VoiceOver on macOS) before shipping.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Cell Templates & Alignment
2+
3+
## Alignment by data type
4+
5+
| Data type | Alignment | Property |
6+
|---|---|---|
7+
| Text | Left | default |
8+
| Numbers | Right | `hAlign="End"` |
9+
| Dates | Right | `hAlign="End"` |
10+
| Boolean | Left | default |
11+
| Links | Left | default |
12+
13+
Set `hAlign` on the `Column` control, not on the cell template.
14+
15+
## Cell template selection
16+
17+
| Content type | Template control |
18+
|---|---|
19+
| Plain text | `sap.m.Text` |
20+
| Formatted number / amount | `sap.m.ObjectNumber` |
21+
| Navigation | `sap.m.Link` |
22+
| Status | `sap.m.ObjectStatus` |
23+
| Icon | `sap.ui.core.Icon` |
24+
25+
## Model type binding
26+
27+
NEVER mix type namespaces. Always match the type namespace to the model:
28+
29+
```xml
30+
<!-- JSON Model -->
31+
<Text text="{path: 'price', type: 'sap.ui.model.type.Float'}"/>
32+
33+
<!-- OData V2 -->
34+
<Text text="{path: 'Price', type: 'sap.ui.model.odata.type.Decimal'}"/>
35+
36+
<!-- OData V4 -->
37+
<Text text="{path: 'Price', type: 'sap.ui.model.odata.v4.type.Decimal'}"/>
38+
```
39+
40+
| Model | Type namespace |
41+
|---|---|
42+
| JSON | `sap.ui.model.type.*` |
43+
| OData V2 | `sap.ui.model.odata.type.*` |
44+
| OData V4 | `sap.ui.model.odata.v4.type.*` |
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Drag & Drop
2+
3+
Configure drag-and-drop on the **table**, not on individual items or cells.
4+
5+
**❌ Wrong — DnD on the item:**
6+
```xml
7+
<Table items="{/products}">
8+
<items>
9+
<ColumnListItem>
10+
<dragDropConfig>
11+
<dnd:DragInfo sourceAggregation="items"/>
12+
</dragDropConfig>
13+
</ColumnListItem>
14+
</items>
15+
</Table>
16+
```
17+
18+
**✅ Correct — reordering within the same table using `DragInfo` + `DropInfo` with matching `groupName`:**
19+
```xml
20+
<Table items="{/products}">
21+
<items>
22+
<ColumnListItem><cells>...</cells></ColumnListItem>
23+
</items>
24+
<dragDropConfig>
25+
<dnd:DragInfo sourceAggregation="items" groupName="reorder"/>
26+
<dnd:DropInfo targetAggregation="items"
27+
groupName="reorder"
28+
dropPosition="Between"
29+
drop=".onDrop"/>
30+
</dragDropConfig>
31+
</Table>
32+
```
33+
34+
**✅ Alternative — using `DragDropInfo` (no `groupName` needed for same-table reorder):**
35+
```xml
36+
<Table items="{/products}">
37+
<dragDropConfig>
38+
<dnd:DragDropInfo sourceAggregation="items"
39+
targetAggregation="items"
40+
dropPosition="Between"
41+
drop=".onDrop"/>
42+
</dragDropConfig>
43+
</Table>
44+
```
45+
46+
## Key rules
47+
48+
- For reordering within the same table: use `DragDropInfo`, or set a matching `groupName` on both `DragInfo` and `DropInfo`.
49+
- For drag between different tables: use matching `groupName` values on both tables.
50+
- Update the bound model in the `drop` handler to reflect the new order.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# sap.ui.table.Table (GridTable)
2+
3+
API: https://ui5.sap.com/1.136.0/api/sap.ui.table.Table
4+
5+
## Minimal complete example
6+
7+
```xml
8+
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:table="sap.ui.table"
9+
controllerName="my.app.controller.Main">
10+
<Page title="Products">
11+
<table:Table id="gridTable" rows="{/products}" selectionMode="MultiToggle"
12+
ariaLabelledBy="gridTableTitle" threshold="100">
13+
<table:extension>
14+
<OverflowToolbar>
15+
<Title id="gridTableTitle" text="Products" level="H2"/>
16+
<ToolbarSpacer/>
17+
<Button icon="sap-icon:action-settings" press=".onPersonalize"/>
18+
</OverflowToolbar>
19+
</table:extension>
20+
<table:rowMode>
21+
<table:rowmodes:Fixed rowCount="10"/>
22+
</table:rowMode>
23+
<table:columns>
24+
<table:Column>
25+
<Label text="Name"/>
26+
<table:template><Text text="{name}" wrapping="false"/></table:template>
27+
</table:Column>
28+
<table:Column hAlign="End">
29+
<Label text="Price"/>
30+
<table:template><ObjectNumber number="{price}" unit="{currency}"/></table:template>
31+
</table:Column>
32+
</table:columns>
33+
</table:Table>
34+
</Page>
35+
</mvc:View>
36+
```
37+
38+
## Key properties
39+
40+
| Property | Type | Default | Since | Notes |
41+
|---|---|---|---|---|
42+
| `selectionBehavior` | SelectionBehavior | RowSelector | 1.0 | `Row`, `RowSelector`, `RowOnly`. |
43+
| `columnHeaderVisible` | boolean | true | 1.0 | Show/hide column headers. |
44+
| `showNoData` | boolean | true | 1.0 | Show "No data" text. |
45+
| `noData` | string / Control || 1.0 | Custom no-data content. |
46+
| `showOverlay` | boolean | false | 1.21 | Block interaction with overlay. |
47+
| `threshold` | int | 100 | 1.0 | Prefetch buffer for virtualization. |
48+
49+
## rowMode aggregation (UI5 1.119+)
50+
51+
Use the `rowMode` aggregation instead of the deprecated `visibleRowCountMode` property.
52+
53+
```xml
54+
<table:rowMode>
55+
<table:rowmodes:Fixed rowCount="10"/>
56+
</table:rowMode>
57+
```
58+
59+
Available row modes: `Fixed`, `Auto`, `Interactive`.
60+
61+
## Selection behavior
62+
63+
- `Row`: selection changed anywhere in the row, including the selector column.
64+
- `RowSelector`: selection changed only via the selector column; row clicks do not select.
65+
- `RowOnly`: selection changed only via row clicks; the selector column is hidden.
66+
67+
Do not call the table's selection API when a `SelectionPlugin` is attached. Use the plugin API instead.
68+
69+
## No-data customization
70+
71+
```xml
72+
<table:Table>
73+
<table:noData>
74+
<IllustratedMessage illustrationType="NoData" title="No Products">
75+
<Button text="Add Product" press=".onAddProduct"/>
76+
</IllustratedMessage>
77+
</table:noData>
78+
</table:Table>
79+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# sap.ui.mdc.Table
2+
3+
API: https://ui5.sap.com/1.136.0/api/sap.ui.mdc.Table
4+
5+
## Delegate pattern
6+
7+
`sap.ui.mdc.Table` uses a delegate for metadata and data operations. Implement both `fetchProperties` and `updateBindingInfo`.
8+
9+
Minimal delegate:
10+
```javascript
11+
sap.ui.define(["sap/ui/mdc/odata/v4/TableDelegate"], function(TableDelegate) {
12+
const MyDelegate = Object.assign({}, TableDelegate);
13+
14+
MyDelegate.fetchProperties = function(oTable) {
15+
return Promise.resolve([
16+
{
17+
key: "name", label: "Name",
18+
dataType: "sap.ui.model.type.String",
19+
sortable: true, filterable: true
20+
},
21+
{
22+
key: "price", label: "Price",
23+
dataType: "sap.ui.model.type.Float",
24+
sortable: true, filterable: true
25+
}
26+
]);
27+
};
28+
29+
return MyDelegate;
30+
});
31+
```
32+
33+
## MDC table usage
34+
35+
```xml
36+
<mdc:Table id="mdcTable" header="Products"
37+
delegate="{name: 'my/app/delegate/TableDelegate', payload: {entitySet: 'Products'}}"
38+
p13nMode="Column,Sort,Filter" autoBindOnInit="true">
39+
<mdc:columns>
40+
<mdc:Column header="Name" propertyKey="name">
41+
<Text text="{name}"/>
42+
</mdc:Column>
43+
<mdc:Column header="Price" propertyKey="price">
44+
<ObjectNumber number="{price}"/>
45+
</mdc:Column>
46+
</mdc:columns>
47+
</mdc:Table>
48+
```

0 commit comments

Comments
 (0)