cancel
Showing results for 
Search instead for 
Did you mean: 

Table is not refreshing after deleting item

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Sharathmg
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Sharath,

Thanks for your suggestion now the app is working fine.

Regards,
Sai Ram Dinesh Pallapotu

Sharathmg
Active Contributor
0 Kudos

Anytime. Welcome.

Answers (2)

Answers (2)

former_member227918
Active Contributor
0 Kudos

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

ashwin_narayan
Participant
0 Kudos

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