cancel
Showing results for 
Search instead for 
Did you mean: 

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

govardan_raj
Contributor

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

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member592880
Participant

hello govardhan,

you could try using filters wherein let the second table have all the data of the second table and after the user clicks on a first table item, using "oEvent" you can get that value and use that to filter the data in the second table.

var that = this;
var oView = that.getView();

var oTable = oView.byId("tab2"),
	oBinding = oTable.getBinding("items"),
	aFilters = [];
var oFilter = new Filter("SUB_TABLE_OBJECT", "EQ", <num>_PART_NO, "X");
	aFilters.push(oFilter);
	// apply filter settings
	oBinding.filter(aFilters);

regards

Siddharth Shaligram