Skip to Content
1
Sep 26, 2019 at 03:06 PM

how to have Nested JSON Array Items Populated in Two Separate Tables

121 Views

hi Team,

I have a requirement , where there is a Main Table & Sub Table. The Main Table has Multiple Items. On selection of an Item in the Main Table , the sub Table should be populated with corresponding data relevant to the selected Item.

data coming from the back end is in the json format.

as shown below , Here SALEORDER_DETAIL Is JsonArray, having SUB_TABLE_OBJECT as JsonArray.

then created a model as shown below

var l_MainTableModel = new sap.ui.model.json.JSONModel();

l_MainTableModel.setProperty("/ITEM",data.SALEORDER_DETAIL);

thisViewPointer.getView().setModel(l_MainTableModel,"CreateSaleOrderItemModel");

In View the Main Table is binded like rows = "{CreateSaleOrderItemModel>/ITEM}"

Sub Table is binded as rows="{CreateSaleOrderItemModel>/ITEM/SUB_TABLE_OBJECT}"

The Main Table is populated with the data. Where as Sub Table is not getting populated , instead it is blank.

Requirement is when User selects first Item, the SubTable should be populated with First Items SUB_TABLE_OBJECT

and on Select Second Item Table , the Sub Table should be populated with Second Items SUB_TABLE_OBJECT

Kindly Help and do the need full.

JSON DATA COMING FROM BACK END
{
"SALEORDER_DETAIL":
	[  
		   {  
			  "NET_VALUE":"3470200.0",
			  "ITEM_NO":"000010",
			  "CREATION_TIME":"16:31:33",
			  "FREIGHT_CHRGS":"1000.0",
			  "PART_NO":"***********",
			  "USER_ID":"***********",
			  "OTHER_TAX":"0.0",
			  "PART_DESC":"123456",
			  "CREDIT_DAYS":"5",
			  "KFC_AMOUNT":"0.0",
			  "SUB_TABLE_OBJECT":
				  {  
					 "000010_PART_NO":
					 [  
						{  
						   "STORAGE_NO":"TEST",
						   "ITEM_NO":"000010",
						   "PART_NO":"*************",
						   "STORAGE_QTY":1
						}
					 ]
				  }
			  ]			   
		   },		   
		   {  
			  "NET_VALUE":"3470200.0",
			  "ITEM_NO":"000020",
			  "CREATION_TIME":"16:31:33",
			  "FREIGHT_CHRGS":"1000.0",
			  "PART_NO":"***********",
			  "USER_ID":"***********",
			  "OTHER_TAX":"0.0",
			  "PART_DESC":"654321",
			  "CREDIT_DAYS":"5",
			  "KFC_AMOUNT":"0.0",
			  "SUB_TABLE_OBJECT":
				  {  
					 "000020_PART_NO":
					 [  
						{  
						   "STORAGE_NO":"TEST123",
						   "ITEM_NO":"000020",
						   "PART_NO":"*************",
						   "STORAGE_QTY":1
						}
					 ]
				  }			   
			  ]			   
		   }
	]
}"

Regards

Govardan Raj