on 08-30-2014 12:33 PM
I have created SAPUI5 application, in that I have loaded data from external .xml file into a table, it was fine. Now, I am trying to delete a specific row from that table.But, I am getting error at the line: `var removed = data.splice(idx, 1);`. However, the same code is good for when model is JSON. How can I delete a specific row from a table when model XMLModel?
Please suggest me to proceed good.
For this purpose, I use this code:
var oModel = new sap.ui.model.xml.XMLModel();
oModel.loadData("Deployments.xml", "", false);
sap.ui.getCore().setModel(oModel);
oTable.bindRows("/service"); // here "service" is the root element of xml file
var oTable= new sap.ui.commons.Button({text:"Delete Service",
press : function() {
var idx = oTable.getSelectedIndex();
if (idx !== -1) {
var m = oTable.getModel();
var data = m.getData();
var removed = data.splice(idx, 1); // error showing at this line
m.setData(data);
sap.m.MessageToast.show(JSON.stringify(removed[0]) + 'is removed');
} else {
sap.m.MessageToast.show('Please select a row');
}
}
});
Thanks
Hi,
The sap.m.Table has property "mode" which can be set to "delete".
Then you can define the functionality in "delete" event of the ListItemBase .
For more info refer to this link:
Regards,
Ritesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
//To delete a row from table
onDelete: function(oEvent){
var m = oEvent.getSource().getParent();
var tbl = this.getView().byId("TableID");
var idx = m.getBindingContextPath();
idx = idx.charAt(idx.lastIndexOf('/')+1);
if (idx !== -1) {
var a = tbl.getModel(); // if named model - var a= tbl.getModel(ModelName);
var data = a.getData();
var removed = data.splice(idx,1);
// Check return value of data.
// If data has an hierarchy. Ex: data.results
// var removed =data.results.splice(idx,1);
a.setData(data);
}
Thanks,
Shamlin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.