Created
August 23, 2014 18:01
-
-
Save dennisseah/972e875ac5d9ae305e56 to your computer and use it in GitHub Desktop.
SAPUI5: sap.ui.table.Table - select all visible rows
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> | |
<!-- sap.ui.table.Table does not render all the rows. It only | |
renders rows that are visible to user. It is commonly | |
for application to select only visible rows. E.g. in | |
email client, select all rows to delete. We only | |
select visible rows | |
--> | |
<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" | |
data-sap-ui-theme="sap_bluecrystal" | |
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"> | |
</script> | |
<script> | |
jQuery(function() { | |
sap.ui.table.Table.extend('selectAllVisibleRowsTable', { | |
renderer : function(oRm, oControl) { | |
sap.ui.table.TableRenderer.render(oRm, oControl); | |
}, | |
selectAllVisibleRowsIndex: function(checkKey) { | |
var model = this.getModel(); | |
var rowPath = this.getBindingInfo('rows').path; | |
var rows = model.getProperty(rowPath); | |
var start = this.getFirstVisibleRow(); | |
var end = Math.min(start + this.getVisibleRowCount(), rows.length); | |
for (var i = 0; i < rows.length; i++) { | |
var row = rows[i]; | |
row[checkKey] = (i >= start && i < end); | |
} | |
this.invalidate(); | |
} | |
}); | |
var oTable = new selectAllVisibleRowsTable({ | |
width: '300px', | |
selectionMode: sap.ui.table.SelectionMode.None | |
}); | |
oTable.addColumn(new sap.ui.table.Column({ | |
label: 'Select', | |
template: new sap.ui.commons.CheckBox({ | |
checked: '{checked}' | |
}) | |
})); | |
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.bindRows('/'); | |
var model = new sap.ui.model.json.JSONModel(); | |
var data = [] | |
for (var i = 0; i < 1000; i++) { | |
data.push({fname: 'fname' + i, lname: 'lname' + i, checked: false}); | |
} | |
model.setData(data); | |
oTable.setModel(model); | |
oTable.placeAt('content'); | |
(new sap.ui.commons.Button({ | |
text: 'Select', | |
press: function(e) { | |
oTable.selectAllVisibleRowsIndex('checked'); | |
} | |
})).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