customData is lost after column move in sap.ui.table.Table
OpenUI5 version: 1.52.13
Browser/version (+device/version): Google Chrome Version 74.0.3729.169 (Official Build) (64-bit)
Any other tested browsers/devices(OK/FAIL): Firefox 67.0 (64-bit)
URL (minimal example if possible): https://next.plnkr.co/plunk/492yWPK0ThkzAWlx
User/password (if required and possible - do not post any confidential information here):
Steps to reproduce the problem:
- Use the + button in the toolbar to add customData (written to DoM) to the first row of the table.
- Check
element of the first row (you will see the newly added customData) - Move a column of the table.
What happens instead? customData set at step 1. is no longer present in the
element. Any other information? (attach screenshot if possible) before: https://ibb.co/wJRTjrK after: https://ibb.co/hR56c3y
Thank you, SePo
Hello seiupo,
Thank you for the issue. It has been tracked internally. You will be updated about its status.
Regards, Alex (UI5)
Hi @seiupo,
We don't really consider this to be an issue, as the rows of the table were never designed to operate with static information on row instance level. Everything regarding the rows of the table needs to be bound.
Could you please explain what you are trying to do by adding custom data to a row?
Thanks
Hi Alexander,
I'm using the customData to write an attribute to the row (visible in the DoM) and then use it to change the color of the row with CSS (I'm aware of a similar possibility to color table cells, but it's not the same thing, especially in TreeTables where the content of the Tree-column is not entirely accessible from the XML View).
Ok, I understand why you don't consider this an issue, but then I think it would be nice to also update the documentation to include a note on this topic. When I first looked over customData documentation and its ability to write data to the DoM, I thought that this data would be persistent; there was no reason to think otherwise (especially for someone that is kind of new to SAPUI5 :-) ).
Last but not least, I'm not familiar with the coding behind the sap.ui.table.Table, but when the Row instances are destroyed and recreated (e.g.: during column move), wouldn't it be possible to create the new row instances based on the old ones and keep settings like customData? It might be that you could even improve the performance if you use the old rows as templates for the new ones.
Cheers, SePo
@seiupo What do the custom row colors represent? Do they have some semantic meaning? In that case, have you considered using the
highlightproperty?
Sample: https://openui5.hana.ondemand.com/#/entity/sap.ui.table.Table/sample/sap.ui.table.sample.RowHighlightsHi Boghyon,
Thank you for pointing me to the RowSettings. I wasn't aware of its existence and it looks quite nice. In my case the colors have indeed a semantic meaning (e.g.: one item has been released or another needs to be replaced). Unfortunately a solution based on RowSettings is not suitable for my use case because I'm highlighting the entire row (it is important to have such a highlight for visibility reasons: the table is not a small one and it contains various cells displaying icons in different colors; by using the highlight property of RowSettings it would be hard for users to notice it).
Additionally, the RowSettings approach is limited to 4 semantic colors. This concerns me as it limits the extending-capabilities of a solution based on RowSettings (e.g.: if I need to highlight rows based on 5 semantic attributes, I need to scrap the RowSettings solution and start from scratch).
Thanks again and have a good day! SePo
I'm using the customData to write an attribute to the row (visible in the DoM) and then use it to change the color of the row with CSS ....
How exactly is this done? I mean, how is the custom data updated when new contexts are applied to the rows, for example when scrolling? Also, the data will only be written to the "main" DOM node of the row. But in case selection, fixed columns or the actions are available, the row can consist of up to 4 nodes (for historical reasons).
... it would be nice to also update the documentation to include a note on this topic.
I agree. There are sill quite some things in this control that need better documentation. :)
... wouldn't it be possible to create the new row instances based on the old ones and keep settings like customData? It might be that you could even improve the performance if you use the old rows as templates for the new ones.
It would be even better for performance to not destroy all the rows, but just update them. This can be done. However, this might not help in your case. There could still be occurrences that make it necessary to fully recreate the rows. Cloning a row and creating a new one from scratch is not that much of a difference from performance perspective. But then there is the additional effort of updating the cloned row.
Hi Alexander,
How exactly is this done? I mean, how is the custom data updated when new contexts are applied to the rows, for example when scrolling? Also, the data will only be written to the "main" DOM node of the row. But in case selection, fixed columns or the actions are available, the row can consist of up to 4 nodes (for historical reasons).
Well here there are some possibilities:
- Using event modelContextChange either on the Row or on one of the Cell-Templates (an example -without the actual coloring- of how this event could be used is available in issue 2532).
- Using events like firstVisibleRowChanged and dataReceived to run a delayed functionality (I know we should not use setTimeout :-), but if you don't have a viable, fast to implement alternative, you do stuff like this :-) ). Here there are some possibilities to make the setTimeout a bit more predictable (e.g.: triggering a table re-render and using event delegates to attach a handler for onAfterRendering)
Setting aside this issue, are there any plans to introduce a standard feature for row-coloring? I believe this would be a much appreciated one!
Cheers, SePo
Quite some effort for a seemingly simple operation.
Actually we do have plans in an early stage to somehow "highlight" rows (not to confuse with the current row highlights). As of now this will probably not be a background color, but a thicker bottom border with predefined colors. Would this fit your use case?
Besides that, if you have the information which background color you want to have for a row in the model, you could extend sap.ui.table.RowSettings to add a property that you can bind. If the property value changes, you could get the row instance and set/update the custom data, or maybe a CSS class. The table's rowSettingsTemplate is cloned to every row, and hence is always available, even if rows are recreated.
Hi Alexander,
Thanks for the RowSettings tip. I'm not sure if I understood this entirely, but in this case, if I use the RowSettings context change, when Row instances are recreated after a column move, I don't expect that a context change will be triggered because RowSettings instance will not be changed. Hence, there will be no way of setting custom data back to the Row after the column move.
Regarding a thicker bottom border, it's better than the RowSettings highlight but the visibility will still be an issue. The bottom border sits between two rows. If you color it, it might be hard for a user to figure out quickly to which row the colored border belongs. If I may suggest, I think it would be better to color all the borders of a row. This way the visibility is better, but then it might look like the row is selected :-) .
Cheers, SePo
I updated your example to demonstrate what i mean. But please do not understand this as an official recommendation how to do this, this is really just a dirty hack. ;) https://next.plnkr.co/edit/Ee5i2JnOomENSskx
Apart from that, we will try to figure out how we could make something like this easier. We will consider the input we got here. However, I can't make any promises,. This is a use case (custom row color) that we don't really want to support for accessibility reasons (color contrast, text announcement).
I'll keep this issue open for now, as we are currently in some internal discussion.
Regards, Alex
Nice example! No worries, I won't take this as an official recommendation :-). Thanks a lot for the hints and for keeping an open mind to community's needs.
Have a good one! SePo
Closing the issue. Because workaround was provided.