DataGrid
A table for large lists: virtual rows, range selection with live totals, inline editing, and copy and paste with Excel.
kor/ui/DataGridSource
When to use
- Users compare, total or edit many rows.
- Rows come from any UI5 list binding: JSON, OData V2 or V4. No template is needed.
When not to use
- Hierarchical data: use TreeGrid.
- A handful of facts about one object: use Stat or Text.
Examples
Orders
500 rows. Drag across amounts to see their total, double-click a customer to edit it.
<k:DataGrid rows="{/orders}" selectionMode="Multi" height="26rem" label="Orders" rowPress=".onOpen" cellChange=".onChange">
<k:columns>
<k:Column label="Order" path="Id" type="link" width="120" pinned="true"/>
<k:Column label="Customer" path="Customer" grow="1" editable="true"/>
<k:Column label="Amount" path="Amount" type="currency" unitPath="Currency" decimals="2"/>
<k:Column label="Due" path="Due" type="date"/>
<k:Column label="Status" path="Status" type="status"
states="{/states}"
formatter=".statusText"/>
</k:columns>
</k:DataGrid>
sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.Grid", {
statusText(value) {
return { open: "Open", late: "Late", done: "Done" }[value];
},
onOpen(event) {
Toast.show(event.getParameter("context").getProperty("Id"));
},
onChange(event) {
Toast.show("Saved: " + event.getParameter("value"));
}
}));
API
Properties
| Name | Type | Default | Description |
|---|
height | sap.ui.core.CSSSize | 32rem | Grid height |
selectionMode | string | None | Row selection mode, None or Multi |
summary | boolean | true | Whether to show the summary bar |
noData | string | | Message shown when there are no rows |
label | string | | Accessible name |
Aggregations
| Name | Type | Description |
|---|
columns | Column[] | Grid columns |
rows | sap.ui.core.Element[] | Rows supplied by a list binding without a template |
Events
| Name | Type | Description |
|---|
rowPress | context: object | A row was opened via a link cell or Enter |
cellChange | context: object
path: string
value: any
oldValue: any | A cell changed. The value has already been written to the model |
stateChange | | Column order, width or sorting changed |
selectionChange | contexts: object | Row selection changed |
Methods
| Name | Description |
|---|
getState(): object | Returns column order, hidden columns, widths and sort order for saving |
setState(state: { order?: string[]; hidden?: string[]; widths?: Record<string, number>; sort?: string; desc?: boolean }): void | Restores saved state and skips unknown columns |
openSettings(opener: Control | HTMLElement): void | Opens column settings next to the supplied opener |
getSelectedContexts(): Context[] | Returns selected row contexts in selection order |
clearSelection(): void | Clears row selection |
Column
A column in a DataGrid or TreeGrid.
Properties
| Name | Type | Default | Description |
|---|
label | string | | Header |
path | string | | Field path relative to the row context |
type | string | text | text, link, number, currency, date, status, progress, person or spark |
width | float | 140 | Width in pixels |
grow | float | 0 | Share of the available extra width |
decimals | int | 0 | Number of decimal places |
unitPath | string | | Path to the unit or currency field |
statePath | string | | Path to a status field with success, wait, danger, info or none |
states | object | | Mapping from cell values to statuses |
options | object | | Choices offered when editing |
editable | boolean | false | Whether cells can be edited |
sortable | boolean | true | Whether the column can be sorted |
pinned | boolean | false | Whether this leading column stays in place during horizontal scrolling |
formatter | function | | Function that formats a value and row context as text |
Related
TreeGridFilterBarVariants