cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to bind Json Data.

Former Member
0 Kudos

Hi Experts,

I have a Json formate like below

{

  "SalesOrderCollection": [

  {

  "SoId": "300000097",

  "ApprovalStatus": "",

  "Status": "Initial",

  "ConfirmationStatus": "",

  "BillingStatus": "Initial"

  "LineItems": [

  {

  "SoItemPos": "300000000",

  "Quantity": "10",

  "GrossAmount": "1137.64",

  "BuyerName": "956.00",

  "TaxAmount": "181.64"

  },

  {

  "SoItemPos": "300000000",

  "Quantity": "20",

  "GrossAmount": "61.88",

  "BuyerName": "52.00",

  "TaxAmount": "9.88",

  }

  ]

  ]

  }

I am able to bind the values from "SalesOrderCollection" array to Table, but i am unable to bind the values from "LineItems" array to the same Table.

Can any one help me how to bind the values from "LineItems" array.

Please find the below code for reference.

<Table growingThreshold="5" growing="true" items="{/SalesOrderCollection}">

   

    <columns>

      <Column>

        <Text text="Product" />

      </Column>

      <Column >

        <Text text="Supplier" />

      </Column>

      <Column>

        <Text text="Dimensions" />

      </Column>

      <Column>

        <Text text="Weight" />

      </Column>

      <Column>

        <Text text="Price" />

      </Column>

</columns>


    <items>

      <ColumnListItem>

        <cells>

         <Input value="{SoId}" />

         <Input value="{ApprovalStatus}" />

         <Input value="{ConfirmationStatus}" />

          <ComboBox items="{trim>/color}" width="8.5rem">

                        <items>

                             <sap.ui.core:Item key="{}" text="{/SalesOrderCollection/LineItems/SoItemPos}"/>

                         </items>

                    </ComboBox>


<Input value="{BillingStatus}" />


        </cells>

      </ColumnListItem>

    </items>

  </Table>

Thanks and Regards

Mohanbabu D

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

Not sure what you're trying to achieve (a dropdown for related data doesn;t make sense) but anyways, your data binding is incorrect:

  • you're binding a combobox item to an absolute path.
    • you should bind it to the combobox itself, and bind the property value to the Item
    • it should be relative to the current table item

I.e.

<ComboBox width="8.5rem" items="{LineItems}">

    <items>

        <core:Item key="{}" text="{GrossAmount}"/>

    </items>

</ComboBox>

Also, why are you using a ComboBox?

Former Member
0 Kudos

Hi Robin,

Thank you very much, its working fine.

Thanks and Regards

Mohanbabu D

Former Member
0 Kudos

HI Robin,

can you please help me, how to get a selected value from a combo box in a Table row.

Thanks and Regards

Mohanbabu D

Qualiture
Active Contributor
0 Kudos

You have to bind it with the related property in your table row data. But again, like I mentioned before, your dropdown values have no relation with your table data. Since your line items are part of the collection, it makes absolutely no sense to have them available in a ComboBox.

The following would make more sense:

Data:

{

   "SalesOrderCollection":

   [

      {

         "SoId": "300000097",

         "ApprovalStatus": "",

         "Status": "Initial",

         "ConfirmationStatus": "",

         "BillingStatus": "Initial",

         "Quantity": 10

      },

      {

         "SoId": "300000098",

         //etc

         "Quantity": 5

      }

   ],

   "Quantities" :

   [

      { "QuantityText": 5 },

      { "QuantityText": 10 },

      { "QuantityText": 20},

      { "QuantityText": 50 }

   ]

}

Binding:

<ComboBox width="8.5rem" value="{Quantity}" items="{/Quantities}">

    <items>

        <core:Item key="{}" text="{QuantityText}"/>

    </items>

</ComboBox>


Also note the absolute slash '/' for the Quantities binding, because the bound data (which is just a list) has no relation to the current data. The bound property 'value' of couse is relative

santhu_gowdaz
Active Contributor
0 Kudos

this may help you,

I'm too worked on the same requirement.

var items = this.getView().byId("TABLEID").getItems();

   for (var i = 0; i < items.length; i++)  

   {     

    var item = items[i];

    sap.ui.getCore().byId(item.getAggregation("cells")[10].getId()).getSelectedKey();

//"10" is My Combobox Column Number in the table.

    }

Qualiture
Active Contributor
0 Kudos

Why so over complicated? Why not simply use databinding? That saves you from writing a single line of code

See my example JSFiddle in the thread you linked to

santhu_gowdaz
Active Contributor
0 Kudos

ya Robin, I agree with you. It's Complicated but i didn't get any idea then this.

And in your example, you are just binded the combobox. but How to get the selected value?

Qualiture
Active Contributor
0 Kudos

Well, via the model of course. And not, I repeat NOT from the table! Never, ever retrieve data from a UI control, whether it's a Text field, or a List, Table, whatever. Always use the model to retrieve data

I mean, how would you get a value from an item which is not visible, due to pagination? Or a user drags a column to a different position?

Either get the value via a control event:


oEvent.getSource().getBindingContext().getObject().Quantity;

or directly via the model:


this.getModel().getProperty("/SalesOrderCollection/3/Quantity"); // if it's item 3 you want

santhu_gowdaz
Active Contributor
0 Kudos

But for multiple records in the table and different selected combobox items.How i can get the particular row combobox selected value.Bec through same model i was bind the combobox in the table.In this case through ComboBox Binded model i can't get the particular row selected key right?

Qualiture
Active Contributor
0 Kudos

Again, via the model. Look at the example I gave, where I set the 'particular row' to 3.

I am absolutely not interested in the bound model (path) for the Select box, only for the model (path) containing the data

EDIT: Have you taken a look at the JSFiddle example in the topic you linked to? All the selected dropdown values are in the model

Answers (0)