Skip to Content

Dynamically add rows and delete rows in sap.m table

I am new to SAPUI5. I have created a Simple form. After submitting the form the details must get added in table dynamically and can also be deleted.While delete operation it shows the error "Cannot read property 'getData' of undefined".

Following is the function of delete.

"delete": function(e)

{

var path = e.getParameter('listItem').getBindingContext("mainModel").getPath();

var idx = parseInt(path.substring(path.lastIndexOf('/') +1));

var oModel = this.getModel();

var oData = oModel.getData();

var removed = oModel.results.splice(idx, 1);

oModel.setData(oData);

}

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Mar 28 at 10:07 AM

    I found out the mistake

    "delete": function(e)

    {

    var path = e.getParameter('listItem').getBindingContext("mainModel").getPath();

    var idx = parseInt(path.substring(path.lastIndexOf('/') +1));

    var oModel = this.getModel("mainModel");

    var oData = oModel.getData("mainModel");

    var removed = oData.results.splice(idx, 1);

    oModel.setData(oData);

    }

    Thanks Drushya & Tri

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 28 at 04:59 AM

    check whether you are getting the model in this way.

    var oModel = this.getModel("mainModel");

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 28 at 04:47 AM

    Hi Mercy,

    I see that you have 2 models: mainModel and "undefined" model. Which one you want to delete records from?

    Regards,

    Tri

    Add comment
    10|10000 characters needed characters exceeded