Skip to Content
0

Table is not refreshing after deleting item

Jul 17, 2017 at 10:17 AM

68

avatar image

Hi,

I am creating a table with delete option with OData model, after clicking on the delete button, updated table is not rendering. Please check attached image for UI and please check below delete button code.

handleDelete: function(oEvent) {
oModel.remove(sPath, {
	success: function(oEvent) {
		sap.m.MessageToast.show("Employee deleted Successfully");
	},
	error: function() {
		sap.m.MessageToast.show("Failed to delete");
	}
});
var oModel1 = new ODataModel("/sap/opu/odata/sap/ZEMPLOYEEPROJ_309_SRV/");
sap.ui.getCore().setModel(oModel1);
var oMod = new sap.ui.model.json.JSONModel();
oMod.loadData("/sap/opu/odata/sap/ZEMPLOYEEPROJ_309_SRV/ZEMPLOYEE309Set?$format=json", null, false, "GET", false, false, null);
sap.ui.getCore().setModel(oMod, "employee");
oList.setModel(oMod);
}

When I refresh browser I can able to see the table with latest binding so please say how to resolve my issue.

Regards,
Sai Ram Dinesh Pallapotu

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Sharath M G Jul 17, 2017 at 10:55 AM
0

Use the method "refresh" on the model. It should refresh the data in the model.

// Remove the entry from the model
// then refresh the model
oModel.refresh();
// Note: If the model is bound to the table then the contents in the table should get refreshed. 

in the delete method, just remove the entry from the model and trigger the refresh and test it. It should reload the data to the boudn controls(which is the table in your case).

Regards,

Sharath

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Sharath,

Thanks for your suggestion now the app is working fine.

Regards,
Sai Ram Dinesh Pallapotu

0

Anytime. Welcome.

0
Akhilesh Upadhyay Jul 18, 2017 at 12:01 PM
0

oModel.refresh() inside success function should work, or just place your refresh (loaddata) code inside success function.

Share
10 |10000 characters needed characters left characters exceeded
Ashwin Narayan Jul 18, 2017 at 11:19 AM
0

Hi Sai Ram,

Ideally using model.refresh(), it should refresh the model and the controls bound to it. But there could be scenario wherein it takes time to update and you might need to show in the table that the deleted record doesn't exist. In this scenario we can use splice.

Steps to achieve this:

  1. Get the table instance in controller
  2. Get the model instance which is bound to the table.
  3. Get a unique value within the record which is to be deleted.

Assuming the one of the key field is a Meter Number which is to be deleted.

for(var i=0;i<MODEL_INSTANCE.METERDATA.length;i++) {

var modelMeterNo=MODEL_INSTANCE.METERDATA[i].Meterno;

if(modelMeterNo==Meter Number Which is selected for deletion) {

MODEL_INSTANCE.METERDATA.splice(i,1);

oModel1.refresh();

Hope it should work !!!

Thanks,

Ashwin

Share
10 |10000 characters needed characters left characters exceeded