cancel
Showing results for 
Search instead for 
Did you mean: 

Add new rows in the sap ui5 table

uppu_narayan
Active Participant
0 Kudos

Hi,

I have a table with aggregation property item set as items="{path:'/trackerSet'}". The data is displayed fine on the table. Now i want to add a new row to this table.

Initial model binding in the init is as below:-

this.sServiceUrl = "proxy/_____/sap/opu/odata/SAP/ZEMPLOYEE_SRV/";

this.oModel = new sap.ui.model.odata.ODataModel(

this.sServiceUrl, true, "", "");

var oView = this.getView().setModel(this.oModel);

Can you please advice.

Regards,

Narayan

Accepted Solutions (1)

Accepted Solutions (1)

former_member365727
Active Contributor
0 Kudos

Hi,

Your JSON model in the view is bit different after this line

oModel.setData({modelData: vData});

Above line creates one more parent node with name as modelData and sets the JSON. Below is the final JSON data:

{
	"modelData": {
		"products": [{
			"product": "Test1",
			"supplier": "Supp1",
			"price": "25"
		}, {
			"product": "Test2",
			"supplier": "supp2",
			"price": "26"
		}]
	}
}

Change table binding to this...

<Table id="idProductsTable" inset="false"
           items="{path: '/modelData/products'}">
uppu_narayan
Active Participant
0 Kudos

Thanks, missed to check on the {modelData: vData} 😄 thanks for pointing out..

Answers (2)

Answers (2)

gowrinath_gundu
Participant

Hello Narayan,

Add a add button to the toolbar of your table, and in the press event of add button call below method

OTable.addItem()

And also in success function of read method, copy the odata into json model and bind this model to view

Hope it works!

Regards,

Gowrinath

uppu_narayan
Active Participant
0 Kudos

I will try on this one for sure.. thanks

junwu
Active Contributor

no possible with odata model. you have to use jsonmodel to do that.

uppu_narayan
Active Participant
0 Kudos

Hi Jun,

Thanks for suggestion, i was doing through simple way using the JSON model and am stuck on the binding; the table says no data. Can you pin point if anything wrong that i am doing.

XML View:-


Controller:-

Regards,

Narayan