cancel
Showing results for 
Search instead for 
Did you mean: 

How to add the additional item data with existing table collection and refreshing?

Jayakrishnan
Active Participant
0 Kudos
881

Hi All,

I am working on SAPUI5 Application development. In my app i am using, sap.ui.table. From OData service, i got an collection, which i consumed, and set an local json model for my further need. I bounded the local json into sapui5 table, i able to see the data.

Later as per my app scenario, i need to add more data into the table row(via button on the table tool bar).once i added the, new rows into the table, i have a save button at the top which should update the latest added entries to the OData Collection, and my table also should be refreshed.

I have a question:

1. How to add the new records with the existing collection(json), in the table?

2. once i added, i called the create entityset. how to update the local json model and table bindings?

Thank you,

Regards,

JK.

0 Kudos

what table are you using ?
Sap.m table or sapui table.

Jayakrishnan
Active Participant
0 Kudos

Both ases i need, i got some solutions. let me try and if that get ok, i post here.

Accepted Solutions (0)

Answers (1)

Answers (1)

smarchesini
Active Contributor
0 Kudos

Hi jayakrishnan.chnadramohan ,

this is my code for adding the simple row of one table with json local model:

addToTable : function (oData) {
//oData is new object

			
				var updateElementPath = this.getView().getModel().createKey(path, {
					"country": oData.country,
					"brand": oData.brand
				});
				var promiseNewCountryBrand = new Promise(function (resolve, reject) {
					sap.ui.core.BusyIndicator.show(0);
					this.getModel().update(updateElementPath, oData, {
						success: function () {
							resolve();
						},
						error: function (msg) {
							reject();
						}
					});
				}.bind(this));
				promiseNewCountryBrand.then(function () {
                                        //here i added the new object in BE system
// now I'm adding to table (json model) MessageToast.show("Update Correctly"); sap.ui.core.BusyIndicator.hide(); var oDataTotal = this._countriesModel.getData(); //json Model oDataTotal.countryList.unshift(oData); var oDataTotalNew = jQuery.extend(true, {}, oDataTotal); oDataTotal.countryList = []; this._countriesModel.setData(oDataTotal); this._countriesModel.refresh(true); //timeout is for sync calling (i know maybe is useless but work) setTimeout(function () { this._countriesModel.setData(oDataTotalNew); setTimeout(function () { this._countriesModel.refresh(true); }.bind(this), 150); }.bind(this), 150); }.bind(this)).catch(function (aError) { sap.ui.core.BusyIndicator.hide(); }); };

Ask me if you don't understand . 🙂

Sebastiano

Jayakrishnan
Active Participant

Thanks Sebastiano Marchesini, I will look at this.