openui5
openui5 copied to clipboard
Enhancement to easily number items rendered with an aggregation binding
Problem
Use ui5 to easily produce a list that looks like this:
Item 1 | 1/3 Item 2 | 2/3 Item 3 | 3/3
OpenUI5 version: Any
Browser/version (+device/version): Any
Any other tested browsers/devices(OK/FAIL):
URL (minimal example if possible): https://gist.github.com/anonymous/247d655e6b9dc6d901804ec2bbd726e9 http://jsbin.com/kuneka/1/edit?html,output
User/password (if required and possible - do not post any confidential information here):
Steps to reproduce the problem:
- Run the jsbin above
What is the expected result? UI5 should have a simple way to number elements when rendering an aggregation. I believe the current best approach for this is to:
- Put the index/total in the model and bind to them. The problem with this is when you can't control the model (e.g. a remote odata service) and you're forced to fill that data;
- Resort to hacks such as directly manipulating dom elements;
- In a json model parse sPath to infer this. Doesn't work on odata and is not efficient
- Use a factory function and keep the counter state in another place (e.g. a controller). You need to remember to clear it elsewhere.
Suggestion
This shouldn't be that hard. I suggest 2 possible ways to make it easier.
- On the factory functions inject a third parameter object with rendering information. This object can then be used to get the current index, total number of items, etc.
- Allow for a new class of expressions in the bindings. For example the django templating language "For" instruction injects a variable called forloop with this data inside the loop ( https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#for ) . In ui5 there could be a "magical" variable that you can bind to e.g. {$loop.index} / {$loop.total}
Any other information? (attach screenshot if possible)
Thanks
Hi, thanks for your message! I am passing this to the responsible product owner to see if there's something we can do. Kind regards Christiane
Hi @tiagobalmeida ,
your issue description does not explain the use case which makes it hard to understand details of a solution. However, the requirement to show index and count in the list has not been raised to us. Also, an internal discussion has shown that an easy out of the box solution on binding level is not possible.
A custom solution seems possible as you have already written but a general custom solution is complicated.
Best regards Mathias.
Hi @tiagobalmeida, as @uhlmannm already explained there are no plans to implement such an enhancement. Therefore closing the issue.