Created
September 21, 2016 14:31
-
-
Save gbvaibhav/b170279952efbf1fac77241e11d21b6c to your computer and use it in GitHub Desktop.
SAPUI5 sap.m.table with adding item with sap.m.Dialog vaibhav gb https://jsbin.com/cuduwe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html><head> | |
<meta name="description" content="SAPUI5 sap.m.table wiht adding item " /> | |
<meta http-equiv='X-UA-Compatible' content='IE=edge' /> | |
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/> | |
<title>SAPUI5 Example gbvaibhav</title> | |
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" | |
id="sap-ui-bootstrap" | |
data-sap-ui-libs="sap.m,sap.ui.layout,sap.ui.core" | |
data-sap-ui-xx-bindingSyntax="complex" | |
data-sap-ui-theme="sap_bluecrystal"></script> | |
<script> | |
var data = { | |
results:[ | |
{}, | |
{ | |
name:"gaurav", | |
place:"mumbai" | |
} | |
] | |
}; | |
var model = new sap.ui.model.json.JSONModel(data); | |
var table = new sap.m.Table({ | |
columns:[ | |
new sap.m.Column({ | |
header:[ | |
new sap.m.Text({text:"Name"}) | |
] | |
}), | |
new sap.m.Column({ | |
header:[ | |
new sap.m.Text({text:"Place"}) | |
] | |
}) | |
] | |
}); | |
var input = new sap.m.Input({ | |
showValueHelp:true, | |
valueHelpRequest:function(oEvent){ | |
dialog.open() | |
} | |
}); | |
var staItem = new sap.m.ColumnListItem({ | |
visible:false, | |
cells:[ | |
input , | |
new sap.m.Text({text:""}) | |
] | |
}) | |
var in1 = new sap.m.Input({}); | |
var in2= new sap.m.Input({}) | |
var dialog = new sap.m.Dialog({ | |
content:[ | |
in1,in2 | |
], | |
beginButton:new sap.m.Button({ | |
text:"add", | |
press:function(){ | |
table.getModel("mainModel").getData().results.push({ | |
name: in1.getValue(), | |
place:in2.getValue() | |
}) | |
table.getModel("mainModel").refresh() | |
staItem.setVisible(false) | |
dialog.close(); | |
} | |
}) | |
}) | |
table.addItem(staItem); | |
table.bindAggregation("items",{ | |
path:"mainModel>/results", | |
template: new sap.m.ColumnListItem({ | |
cells:[ | |
new sap.m.Text({text:"{mainModel>name}"}), | |
new sap.m.Text({text:"{mainModel>place}"}) | |
] | |
}) | |
}); | |
table.setModel(model, "mainModel") | |
var button= new sap.m.Button({ | |
text:"Add", | |
press:function(oevent){ | |
staItem.setVisible(true); | |
} | |
}) | |
var page = new sap.m.Page({ | |
title:"SAPUI5 Example gbvaibhav", | |
content:[ | |
table,button | |
] | |
}); | |
// finally place the App into the UI | |
var app = new sap.m.App({ | |
pages: [page] | |
}).placeAt("content"); | |
</script> | |
</head> | |
<body> | |
<div id='content'></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment