FilterBar
Turns user input into UI5 filters for a list binding.
When to use
- Let users narrow the same list by text, discrete values or numeric comparisons.
Examples
Add or remove a token
Loading the example
<k:FilterBar placeholder="Type a customer name" change=".onFilter">
<k:FilterField label="Customer" path="customer"/>
</k:FilterBar>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.CustomerFilter", {
onFilter(event) {
Toast.show(event.getParameter("filters").length ? "Filter applied" : "Filters cleared");
}
}));Filter the order grid
Type “Aster” or “>5000”, then choose a suggestion. Remove the token to see all orders again.
Loading the example
<k:Stack gap="10">
<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.OrderFilter", {
onFilter(event) {
this.byId("grid").getBinding("rows").filter(event.getParameter("filters"));
Toast.show("Order list updated");
}
}));API
Properties
| Name | Type | Default | Description |
|---|---|---|---|
placeholder | string | Search placeholder |
Aggregations
| Name | Type | Description |
|---|---|---|
fields | FilterField[] | Fields available for filtering |
Events
| Name | Type | Description |
|---|---|---|
stateChange | Serializable filter state changed | |
change | filters: object | Filters changed. Pass filters directly to ListBinding.filter |
Methods
| Name | Description |
|---|---|
getFilters(): Filter[] | Returns active filters, OR within a field and AND across fields |
addToken(path: string, op: Token["op"], value: string | number): void | Adds a filter token programmatically |
clear(): void | Removes all tokens |
getState(): object | Returns filter state for saving |
setState(state: { path: string; op: Token["op"]; value: string | number }[]): void | Restores saved filter state |
FilterField
A field available in a FilterBar.
Properties
| Name | Type | Default | Description |
|---|---|---|---|
label | string | Field label | |
path | string | Model path | |
type | string | text | text, number or option |
options | object | Available choices | |
unit | string | Unit displayed with a numeric value |