Skip to content

Instantly share code, notes, and snippets.

@dennisseah
Created August 29, 2014 03:35
Show Gist options
  • Save dennisseah/067a6c8998b9881399a3 to your computer and use it in GitHub Desktop.
Save dennisseah/067a6c8998b9881399a3 to your computer and use it in GitHub Desktop.
SAPUI5: Demonstrates two ways binding on sap.ui.table.Table
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script id="sap-ui-bootstrap"
type="text/javascript"
data-sap-ui-libs="sap.ui.table,sap.ui.commons,sap.m"
data-sap-ui-theme="sap_bluecrystal"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js">
</script>
<script>
jQuery(function() {
var oTable = new sap.ui.table.Table({
width: '300px',
selectionMode: sap.ui.table.SelectionMode.None
});
oTable.addColumn(new sap.ui.table.Column({
label: 'First Name',
template: new sap.ui.commons.TextField({
value: '{fname}'
})
}));
oTable.addColumn(new sap.ui.table.Column({
label: 'Last Name',
template: new sap.ui.commons.TextField({
value: '{lname}'
})
}));
oTable.addColumn(new sap.ui.table.Column({
label: 'Amount',
template: new sap.ui.commons.TextField({
value: '{amount}'
})
}));
oTable.bindRows('/');
var model = new sap.ui.model.json.JSONModel();
model.setData([
{fname: 'Joe', lname: 'Bloggs', amount: 20},
{fname: 'Kele', lname: 'Kyle', amount: 20},
{fname:'Kom', lname: 'Mary', amount: 30}
]);
oTable.setModel(model);
oTable.placeAt('content');
(new sap.ui.commons.Button({
text: 'Change',
press: function() {
var model = oTable.getModel();
var data = model.getData();
data[0]['amount'] = parseInt(data[0]['amount']) +10;
model.setData(data);
}
})).placeAt('content');
});
</script>
</head>
<body class="sapUiBody">
<div style="margin:10px;">
Edit the Amount value in the first row. Click on the Change button to add 10 to the value
</div>
<div id="content"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment