Skip to Content
avatar image
Former Member

Table is not refreshing after deleting item

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jul 17, 2017 at 10:55 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 18, 2017 at 12:01 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 18, 2017 at 11:19 AM

    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

    Add comment
    10|10000 characters needed characters exceeded