Variants
Saves and reapplies named views of connected controls.
When to use
- Let users return to a set of filters or a grid layout they use frequently.
Examples
Save a grid view
Sort a column, save the view, then use the menu to switch between the standard and saved views.
Loading the example
<k:Stack gap="10">
<k:Stack row="true" gap="8">
<k:Variants id="views" targets="grid" standardText="Standard orders"/>
<k:Button text="Save current view" press=".onSave"/>
</k:Stack>
<k:DataGrid id="grid" rows="{/orders}" height="13rem" label="Orders">
<k:columns>
<k:Column label="Order" path="id" width="100"/>
<k:Column label="Customer" path="customer" grow="1"/>
<k:Column label="Amount" path="amount" type="number"/>
</k:columns>
</k:DataGrid>
</k:Stack>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.GridVariants", {
onSave() {
this.byId("views").saveAs("My order list");
Toast.show("View saved");
}
}));Restore an order filter
Choose the supplied view to filter to Aster orders. Bind variants and listen for change if the application manages storage.
Loading the example
<k:Stack gap="10">
<k:Variants targets="filter grid" variants="{/views}" select=".onSelect"/>
<k:FilterBar id="filter" placeholder="Search customers or amounts" change=".onFilter">
<k:FilterField label="Customer" path="customer"/>
<k:FilterField label="Amount" path="amount" type="number" unit="TRY"/>
</k:FilterBar>
<k:DataGrid id="grid" rows="{/orders}" height="13rem" label="Orders">
<k:columns>
<k:Column label="Order" path="id" width="100"/>
<k:Column label="Customer" path="customer" grow="1"/>
<k:Column label="Amount" path="amount" type="number"/>
</k:columns>
</k:DataGrid>
</k:Stack>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.OrderVariants", {
onFilter(event) {
this.byId("grid").getBinding("rows").filter(event.getParameter("filters"));
},
onSelect(event) {
Toast.show(event.getParameter("key") === "aster" ? "Aster orders" : "Standard orders");
}
}));API
Properties
| Name | Type | Default | Description |
|---|---|---|---|
variants | object | null | Array of saved views |
selectedKey | string | standard | Key of the selected view |
standardText | string | Label of the standard view | |
storageKey | string | Browser storage key. Empty disables browser storage | |
shareable | boolean | false | Whether to offer the share option |
title | boolean | false | Whether to use heading typography |
Associations
| Name | Type | Description |
|---|---|---|
targets | sap.ui.core.Control[] | Controls whose state is saved and restored |
Events
| Name | Type | Description |
|---|---|---|
change | variants: object | Saved views changed through creation, removal, rename or default selection |
select | key: string | A saved view was applied |
Methods
| Name | Description |
|---|---|
apply(key: string): void | Applies the view with the supplied key |
saveAs(name: string, options: { isDefault?: boolean; shared?: boolean } = {}): void | Saves the current state under a new name |
save(): void | Overwrites the selected view with the current state |
type Variant = { key: string; name: string; state: Record<string, unknown>; isDefault?: boolean; shared?: boolean; locked?: boolean };