cancel
Showing results for 
Search instead for 
Did you mean: 

How can I delete the row of treetable by the button press

0 Kudos

Hi,

My requirement is to delete the treetable row while clicking cancel button..This is my press function code.

	onDelete:function(evt)
		{
			var sPath = evt.getSource().getBindingContext().getPath();
		
		  
		    var oObj = this.getView().getModel().getObject(sPath);
		    console.log();
		    sPath.remove();
		    this.getView().getModel().refresh();
		}

Here I am getting error like remove of undefined.

Can anyone help ?

Thanks,

Rahul

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member191660
Participant
0 Kudos

Hi Rahul,

sPath is a String, so sPath.remove() will fail anyway,

moreover, if the Model has a name, you should call .getBindingContext('modelname').getPath()

Sergei

0 Kudos

Again same error is coming....

onDelete:function(evt)
		{
			var sPath = evt.getSource().getBindingContext("demoModel").getPath();
		    var oObj = this.getView().getModel("demoModel").getObject(sPath);
		    oObj.remove();
		    this.getView().getModel("demoModel").refresh();
		}
former_member191660
Participant
0 Kudos

place a breakpoint after yougot sObj and oberve it. sObj will bei some sort of JSON Object.

if you want to remove the element from the model, use ...getModel("demoModel").remove(sPAth)

see more in documentation: https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/remove

if you need to submit the changes to the backend, you will also need something like ...getModel("demoMOdel").submitChanges()