<Table headerText="Products data" class="sapUiMediumMargin">
<columns>
<Column>
<header>
<Text text="Items"></Text>
</header>
<footer>
<Text text="Total"></Text>
</footer>
</Column>
<Column>
<header>
<Text text="Price"></Text>
</header>
<footer>
<Text id="total"></Text>
</footer>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="Item1"></Text>
<Input id="input1" type="Number"></Input>
</cells>
</ColumnListItem>
<ColumnListItem>
<cells>
<Text text="Item2"></Text>
<Input id="input2" type="Number"></Input>
</cells>
</ColumnListItem>
</items>
</Table>
<Bar>
<contentMiddle>
<Button text="Calculate" icon="sap-icon://simulate" press="calculate" class="sapUiLargeMargin"></Button>
</contentMiddle>
</Bar>
calculate: function () {
var item1Value = this.getView().byId("input1").getValue();
var item2Value = this.getView().byId("input2").getValue();
var total = Number(item1Value) + Number(item2Value);
this.getView().byId("total").setText(total);
},
<content>
<Table items="{productsModel>/products}" id="tableProd" class="sapUiMediumMargin">
<columns>
<Column id="ProductId">
<Text text="Product ID"></Text>
</Column>
<Column id="ProductName">
<Text text="Product name"></Text>
</Column>
<Column id="Category">
<Text text="Category"></Text>
</Column>
<Column id="Price">
<Text text="Price"></Text>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Label text="{productsModel>ProductId}"></Label>
<Label text="{productsModel>ProductName}"></Label>
<Label text="{productsModel>Category}"></Label>
<Label text="{productsModel>Price}"></Label>
</cells>
</ColumnListItem>
</items>
</Table>
<Bar>
<contentMiddle height="100%">
<Button text="Calculate" icon="sap-icon://simulate" press="onClick" class="sapUiLargeMargin"></Button>
</contentMiddle>
</Bar>
</content>
{
"products": [{
"ProductId": "1",
"ProductName": "Name1",
"Category": "Category1",
"Price": "100"},
{
"ProductId": "2",
"ProductName": "Name2",
"Category": "Category2",
"Price": "120"},
{
"ProductId": "3",
"ProductName": "Name3",
"Category": "Category3",
"Price": "140"},
{
"ProductId": "4",
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
onInit: function () {
var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData("./model/products.json");
this.getView().setModel(oModel, "productsModel");
},
onClick: function () {
var sum = 0,
items = this.getView().byId("tableProd").getItems();
for (var i = 0; i < items.length; i++) {
sum = sum + Number(items[i].getBindingContext("productsModel").getObject().Price);
}
MessageBox.show("The total price:" + " " + sum);
}
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 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |