Skip to Content
0

How to transpose a json data from rows to column(Rows to column conversion) ?

Mar 08 at 05:34 AM

205

avatar image
Former Member

Hi Experts,

I have a odata service entity set for a material list , Which has rows for each period for a particular material.

Structure:
Material1
Period1
Quantity1

Materail1
Period2
Quantity2

Material1
Period3
Quantity3

Materail2
Period1
Quantity1

Material2
Period2
Quantity2
I need to feed this as json model data to sap.ui.table,
and the it should transpose rows to columns ,and display of content will be,
Material    Period1    Period2    Period3
Material1   Qunatity1  Quantity2  Quantity3
Material2   Qunatity1  Quantity2  0
How this can be achieved from the in Sap ui5 ?

Thanks In advance,

Sandeep

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Sergio Guerrero Mar 10 at 08:41 PM
0

in sapui5....

you could read the odata model... and create a local json model in your app...

1) read the first row -- data[0] -- assuming you have at least one row in your data array

2) get the object properties -- js code: Object.keys(data[0]); // this will give your the column names from the object properties

3) read every row after that and add it to an array inside the model --

hope this guidance helps

Share
10 |10000 characters needed characters left characters exceeded
Nithin Uppila Mar 09 at 05:20 AM
0

Hi Sandeep,

Please refer the following link https://blogs.sap.com/2017/07/10/pivot-data-in-hana/ , this might be useful for you.

Thanks,
Nithin

Share
10 |10000 characters needed characters left characters exceeded