You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We add the invoice list controller to the view to get access to the view model we defined in the controller.
48
48
49
-
We add a price and the currency to our invoices list in the view by adding the `number` attribute to the `ObjectListItem` control, then we apply the currency data type on the number by setting the `type` attribute of the binding syntax to `sap.ui.model.type.Currency`. The `Currency` type will handle the formatting of the price for us, based on the currency code. In our case, the price is displayed with 2 decimals.
49
+
We add a price and the currency to our invoices list in the view by adding the `number` attribute to the `ObjectListItem` control. To apply the currency data type, we use the `require` attribute with the namespace URI `sap.ui.core`, for which the prefix `core` is already defined in our XML view. This allows us to write the attribute as `core:require`. We then add the currency data type module to the list of required modules and assign it the alias `Currency`, making it available for use within the view. Then we set the `type` attribute of the binding syntax to the alias `Currency`. The `Currency` type will handle the formatting of the price for us, based on the currency code. In our case, the price is displayed with 2 decimals.
50
50
51
51
Additionally, we set the formatting option `showMeasure` to `false`. This hides the currency code in the property `number`. Instead we pass the currency on to the `ObjectListItem` control as a separate property `numberUnit`.
@@ -62,13 +63,16 @@ Additionally, we set the formatting option `showMeasure` to `false`. This hides
62
63
items="{invoice>/Invoices}" >
63
64
<items>
64
65
<ObjectListItem
66
+
core:require="{
67
+
Currency: 'sap/ui/model/type/Currency'
68
+
}"
65
69
title="{invoice>Quantity} x {invoice>ProductName}"
66
70
number="{
67
71
parts: [
68
72
'invoice>ExtendedPrice',
69
73
'view>/currency'
70
74
],
71
-
type: 'sap.ui.model.type.Currency',
75
+
type: 'Currency',
72
76
formatOptions: {
73
77
showMeasure: false
74
78
}
@@ -102,6 +106,8 @@ As you can see above, we are using a special binding syntax for the `number` pro
102
106
103
107
[Formatting, Parsing, and Validating Data](https://sdk.openui5.org/topic/07e4b920f5734fd78fdaa236f26236d8.html"Data that is presented on the UI often has to be converted so that is human readable and fits to the locale of the user. On the other hand, data entered by the user has to be parsed and validated to be understood by the data source. For this purpose, you use formatters and data types.")
104
108
109
+
[Require Modules in XML View and Fragment](https://sdk.openui5.org/topic/b11d853a8e784db6b2d210ef57b0f7d7.html"Modules can be required in XML views and fragments and assigned to aliases which can be used as variables in properties, event handlers, and bindings.")
@@ -36,13 +37,16 @@ We add the `numberState` attribute to the `ObjectListItem` control in our invoic
36
37
items="{invoice>/Invoices}" >
37
38
<items>
38
39
<ObjectListItem
40
+
core:require="{
41
+
Currency: 'sap/ui/model/type/Currency'
42
+
}"
39
43
title="{invoice>Quantity} x {invoice>ProductName}"
40
44
number="{
41
45
parts: [
42
46
'invoice>ExtendedPrice',
43
47
'view>/currency'
44
48
],
45
-
type: 'sap.ui.model.type.Currency',
49
+
type: 'Currency',
46
50
formatOptions: {
47
51
showMeasure: false
48
52
}
@@ -78,4 +82,4 @@ Expressions are limited to a particular set of operations that help formatting t
78
82
79
83
**Related Information**
80
84
81
-
[Expression Binding](https://sdk.openui5.org/topic/daf6852a04b44d118963968a1239d2c0.html"Expression binding is an enhancement of the OpenUI5 binding syntax, which allows for providing expressions instead of custom formatter functions.")
85
+
[Expression Binding](https://sdk.openui5.org/topic/daf6852a04b44d118963968a1239d2c0.html"Expression binding is an enhancement of the OpenUI5 binding syntax, which allows for providing expressions instead of custom formatter functions.")
0 commit comments