Skip to Content

How remove item from Model?

Hey guys.

I want remove item from model.

I finded this code;

for(var i=0; i<aSelectedItems.length; i++){
   var oItemContextPath = aSelectedItems[i].getBindingContext().getPath()
   var aPathParts = oItemContextPath.split("/");
   var iIndex = aPathParts[aPathParts.length - 1]; //Index to delete into our array of objects
   var oJSONData = this.getView().getModel().getData();
   oJSONData.correlationData.splice(iIndex, 1); //Use splice to remove your object in the array
   this.getView().getModel().setData(oJSONData); //And set the new data to the model
 }

And i using this;

var oTable = this.getView().byId("mesaiTable");
var sSelectedItems = oTable.getSelectedItems();
var oModel = this.getView().getModel();
var oTempData = oModel.getData(); **//THIS CODE RETURNING 'UNDEFINED'******

for (var i = 0; i < sSelectedItems.length; i++) {
var oItemContextPath = sSelectedItems[i].getBindingContext().getPath();
var aPathParts = oItemContextPath.split("/");
var iIndex = aPathParts[aPathParts.length - 1];
oTempData.XXXX.splice(iIndex, 0); ---> And I dont know XXXX. Table items Path? or not ?

Please help. Just I want delete item from model.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Dec 27, 2017 at 08:03 AM

    Hi,

    If you're trying to remove rows from the table. then it as below.

    var oTempData = oTable.getModel().getData();
    // Now get the selected index and split it.
    oTempData.results.splice(iIndex, 0);
    
    Add comment
    10|10000 characters needed characters exceeded

  • Dec 27, 2017 at 02:44 PM

    Hi Burak,

    Declare a delete handler on your table just like this document explains.

    Once you have declared the event handler, you need to retrieve the selected row and remove it from the model just like explained on this sample for a List item. The only difference is that you need to get the selected "rows". Now for this it depends on which sapui5 element you are using as Table.

    sap.ui.table.Table:

    var bindInfo = oTable..getSelectedItems().getBindingInfo("rows")

    sap.m.Table:

    var bindInfo = oTable..getSelectedItems().getBindingInfo("items")

    Now you can retrieve the path to your model from the bindInfo object like this:

    this.oJsonModel.remove(bindInfo.path);

    Regards,
    Ivan

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 26, 2017 at 09:55 PM

    Hello,

    Is your model come from an OData, if so use your back end to do it.

    Otherwise did you look at this blog : Link

    Regards,

    Joseph

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 29, 2017 at 01:41 AM

    var oModel = this.getView().getModel();

    should be

    var oModel = oTable.getModel();

    and here is a simple example, http://jsbin.com/pulenom/edit?html,js,output

    Add comment
    10|10000 characters needed characters exceeded