Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Mar 10 at 08:41 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 09 at 05:20 AM

    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

    Add comment
    10|10000 characters needed characters exceeded