A quick look at handling changing values, e.g. decimal places, and binding them into views.
Recently, we come across a very unique requirement. The requirement is as follow:
To display a currency value, with varying precision and scale depending on what is maintained on the database.
On initial investigation, this may look like a pretty straightforward approach of odata model and SAPUI5 data binding. But, upon technical walkthrough, the requirements force us not to maintain the values on
SEGW. This is due to the fact that the precision and scale are dynamic values from another table.
For us to maximize the SAPUI5 binding capability, we’ve decided to indicate the precision and scale as
properties of the entity type in our service.
In this way, we can still utilize the binding, and fill out the precision and scale dynamically from the tables.
Once we’ve converted the precision and scale to a property, we can now use them for binding in our SAPUI5 views. To be more specific, we also utilize the
change event on SAPUI5 controller.
In this approach, we minimize hard coding and additional processing of properties. We also maximize data binding events and all of the UI elements are intact since we still get the values from the context.
This approach is not only limited to use cases such as decimal places but in any field that is dynamic in terms of values.
In making applications, we focus on leveraging the binding events and contexts, since all of this is managed by SAPUI5. Rather than creating own
formatters this enables us to maintain data on the backend side, and let the application display or present it without any additional changes.
How about you? How will you tackle this kind of requirements?
Let me know in the comment section below and don’t forget to subscribe for more SAPUI5 content. 🙂