cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

SergioG_TX
Active Contributor
0 Kudos

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

nithinu
Participant
0 Kudos

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