Hello SAP Community,
I want to be able to concatenate multiple items from an oData array in a single cell of a column in the sap.ui.table.Table.
To clarify, lets say I have oData array with 20 elements. Each element has 40 items. Now if a bind this to the sap.ui.table.Table i do not want 40 columns as its too much data and makes the table too busy. So I want to loop through the model and concatenate several columns' text into one string and place that string into just one column of the table. Also, the Table only shows the first 10 rows until the user scrolls. So when the application first loads my model has 20 elements and calling this function only returns the first 10 rows.
var oTableRows = this.getView().byId("testTable").getRows();
My initial thought was to iterate over the array, concatenate the string and then iterating through oTableRows and inserting the concatenated string by getting the correct cell in each row. But then I'd only be able to do it for the first 10 and not the remaining 10 rows. Also the tavle has a sort function. So if the user sorts on the table and then I call the above function, it will return rows in a different order to what the model is in so I couldn't simply insert the concatenated string in the order the table is in. What is the best way to achieve what I am trying to do? I need to make sure that the concatenated string is inserted into all the rows right immediately after the model is read and bounded to the table. Is the a better way?
Thank you all for your suggestions and feedback in advance.
D
Request clarification before answering.
Hi Daniel,
i am not 100% sure if i get your requirements correctly, but are you looking for sth. that looks like this:

For that, you don't have to actually concatenate strings through looping (sorting and ordering would not work too). You could just bind each entity to what you want in the column by placing the text fields inside a VBox, which sets the structure for the column item:
<table:Column width="14em">
<Label text="Multiple fields per cell"/>
<table:template>
<VBox>
<Text text="Oldvalue: {custom>SupplierID}"/>
<Text text="NewValue: {custom>CategoryID}"/>
<Text text="Field3: {custom>UnitsInStock}"/>
</VBox>
</table:template>
</table:Column>
Basically, you could do many things with columns cells, they don't have to be just one single text, even though this is the standard use. You could even implement sorting and filtering on the column for one specific property (e.g. OldValue2).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are probably looking for something like this, right?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vinicius,
WOW! This looks really helpful and I think it will get me started along the correct path! Thank you very much for sharing this.
Do you know if it is somehow possible to put each concatenated result on a new line in the cell? The escape character "\n" doesn't seem to work in either sap.m.Text or sap.m.Label. What I'm trying to achieve is something like:
Old Value: value, New Value: value,
Old Value: value, New Value: value,
Old Value: value, New Value: value,
in one cell rather than:
Old Value: value, New Value: value, Old Value:
value, New Value: value, Old Value: value,
New Value: value.
Thanks again!
D
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.