
{
"results": {
"ColumnData": [{
"Column": "Material"
}, {
"Column": "Description"
}, {
"Column": "Quantity"
}, {
"Column": "Value"
}],
"rowData": [{
"Material": "0001",
"Description": "textails",
"Quantity": "5",
"Value": "1000"
}, {
"Material": "0002",
"Description": "Iron",
"Quantity": "25",
"Value": "10000"
}, {
"Material": "0003",
"Description": "medical",
"Quantity": "51",
"Value": "100000"
}, {
"Material": "0004",
"Description": "plastic",
"Quantity": "53",
"Value": "100000"
}, {
"Material": "0005",
"Description": "dispocals",
"Quantity": "45",
"Value": "990000"
}]
}
}
onInit: function () {
var that = this;
var modelData = new JSONModel(jQuery.sap.getModulePath("com.TablefromController",
"/model/Data.json"));
that.getView().setModel(modelData, "TableData");
var oTable = new Table("Table", {alternateRowColors: true});
oTable.setModel(modelData, "TableData");
that.getView().byId("oPage").addContent(oTable);
oTable.bindAggregation("columns", "TableData>/results/ColumnData", function
(index, context) {
return new sap.m.Column({
header: new sap.m.Label({
text: context.getObject().Column
})
});
});
oTable.bindItems("TableData>/results/rowData", function (index, context) {
var obj = context.getObject();
var row = new ColumnListItem();
for (var i in obj) {
row.addCell(new Text({
text: obj[i]
}));
}
return row;
});
this.getView().byId("oPage").addContent(oTable);
}
//adding custom button to the header content of page
var oButton = new sap.m.Button("Export", {
icon: "sap-icon://excel-attachment",
text: "Export", type: "Emphasized",
press: function () {
that.onExport();
});
that.byId("oPage").addHeaderContent(Button);
onExport: function (oEvent) {
//varibles related to spreedsheet
var acols, Settings, Sheet;
var collection Record = this.getView().getModel("TableData").getData().results.rowData;
//calling columns event in order to get that colums
acols = this.createColumnConfig();
//geting hole data from model
oSettings = {
workbook : {
columns: acols, context: {
sheetName: "Dynamic Data"
dataSource: collectionRecord,
fileName: "Dynamic Data"
//created spreedsheet
oSheet = new Spreadsheet(osettings);
OSheet.build()
.then(function () {
// Message Toast.show("Spreadsheet export has finished);
.finally(function () {
Sheet.destroy();
});
createColumnConfig: function() {
var data = this.getView().getModel("TableData").getData().results;
var PropertyData = data.ColumnData;
var arr = [];
var obj = {};
for (var i = 0; i < PropertyData.length; i++) {
obj.label = PropertyData[i].column;
obj.property = PropertyData[i].Column;
obj.type = "string";
var sobj = JSON.stringify(obj);
arr.push(sobj);
}
var columnProperties = arr.map(function(value) {
return JSON.parse(value);
});
return columnProperties;
}
<mvc:View controllerName="com.TablefromController.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m">
<App>
<pages>
<Page title="{i18n>title}" id="oPage">
<content></content>
</Page>
</pages>
</App>
</mvc:View>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
7 | |
7 | |
6 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 |