<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="tableinsert.Main" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Title">
<content>
<Table id="ins" items="{/Products}">
<headerToolbar>
<Toolbar>
<Button icon="sap-icon://add" text="Row" press="addRow"/>
<Button icon="sap-icon://display" text="Row" press="fetchRecords"/>
</Toolbar>
</headerToolbar>
<columns>
<Column width="50px"/>
<Column>
<Text text="Product" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true"
>
<Text text="Dimensions" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Button icon="sap-icon://delete" press="deleteRow" type="Reject"/>
<Input value="{Name}"/><Input value="{size}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
</Page>
</core:View>
onInit: function() {
this._data = {
Products : [
{ Name : 'Clock' , size : '1X2X5'},
{ Name : 'Pen' , size : '7X2X5'}
]
};
this.jModel = new sap.ui.model.json.JSONModel();
this.jModel.setData(this._data);
},
onBeforeRendering: function() {
this.byId('ins').setModel(this.jModel);
},
addRow : function(oArg){
this._data.Products.push({Name : '', size : ''});
this.jModel.refresh();//which will add the new record
},
deleteRow : function(oArg){
var deleteRecord = oArg.getSource().getBindingContext().getObject();
for(var i=0;i<this._data.Products.length;i++){
if(this._data.Products[i] == deleteRecord )
{
// pop this._data.Products[i]
this._data.Products.splice(i,1); //removing 1 record from i th index.
this.jModel.refresh();
break;//quit the loop
}
}
},
fetchRecords : function(oArg){
//data will be in this._data.Products
console.log(this._data.Products);
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
9 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |