Created
August 27, 2014 07:53
-
-
Save dennisseah/07e977f1a23f926fd1e2 to your computer and use it in GitHub Desktop.
SAPUI5: Add two Links to one column in sap.ui.table.Table
This file contains hidden or 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 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> | |
| $(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: 'Action', | |
| template: new sap.ui.commons.layout.HorizontalLayout({ | |
| content: [ | |
| new sap.ui.commons.Link({ | |
| text: 'Remove', | |
| press: function(e) { | |
| var tbl = this.getParent().getParent(); | |
| var m = tbl.getModel(); | |
| var d = m.getData(); | |
| var path = this.getBindingContext().getPath(); | |
| var idx = parseInt(path.substring(path.lastIndexOf('/')+1)); | |
| var removed = d.splice(idx, 1); | |
| m.setData(d); | |
| sap.m.MessageToast.show(removed[0].fname + ' is removed'); | |
| } | |
| }), | |
| new sap.ui.commons.Link({ | |
| text: 'Edit', | |
| press: function(e) { | |
| var tbl = this.getParent().getParent(); | |
| var m = tbl.getModel(); | |
| var path = this.getBindingContext().getPath(); | |
| var obj = m.getProperty(path); | |
| sap.m.MessageToast.show('edit: ' + JSON.stringify(obj)); | |
| } | |
| }) | |
| ] | |
| }).addStyleClass('spaceout') | |
| })); | |
| oTable.bindRows('/'); | |
| var model = new sap.ui.model.json.JSONModel(); | |
| model.setData([ | |
| {fname: 'Joe', lname: 'Bloggs'}, | |
| {fname: 'Kele', lname: 'Kyle'}, | |
| {fname:'Kom', lname: 'Mary'} | |
| ]); | |
| oTable.setModel(model); | |
| oTable.placeAt('content'); | |
| }); | |
| </script> | |
| </head> | |
| <body class="sapUiBody"> | |
| <div id="content"></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment