<mvc:View controllerName="p13nDialog.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}">
<content>
<Button text="p13NBut
<Table id="AssetTable
<columns>
<Column demandPopin="true" minScreenWidth="Tablet" popinDisplay="Inline"
visible="{columns>visible}" width="100%">
<Text text="{columns>columnKey}"/>
</Column>
</columns>
<ColumnListItem>
<cells>
<Text text="Product ID "/>
<Text text="Name"/>
<Text text="Category"/>
<Text text="Supplier Name"/>
<Text text="Description"/>
<Text text="10"/>
<Text text="5"/>
<Text text="50"/>
<Text text="Status"/>
</cells>
</ColumnListItem>
</Table>
</content>
</Page>
</pages>
</App>
</mvc:View>
{
"ColumnCollection": [{
"columnKey": "Product ID",
"visible": true
}, {
"columnKey": "Name",
"visible": true
}, {
"columnKey": "Category",
"visible": true
}, {
"columnKey": "Supplier Name",
"visible": false
}, {
"columnKey": "Description",
"visible": true
}, {
"columnKey": "Weight Measure",
"visible": false
}, {
"columnKey": "Weight Unit",
"visible": false
}, {
"columnKey": "Price",
"visible": false
}, {
"columnKey": "Status",
"visible": false
}]
}
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("p13nDialog.controller.View1", {
onInit: function() {
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.loadData("model/columns.json");
this.getView().setModel(oJSONModel, "columns");
},
});
});
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<P13nDialog showReset="true" showResetEnabled="true" ok="onOK"
cancel="onCancel" reset="onReset" class="sapUiSizeCompact" >
<panels>
<P13nColumnsPanel items="{path: 'p13Dialog>/ColumnCollection'}"
columnsItems="{path: 'p13Dialog>/ColumnCollection'}">
<items>
<P13nItem columnKey="{p13Dialog>columnKey}" text="{p13Dialog>columnKey}"/>
</items>
<columnsItems>
<P13nColumnsItem columnKey="{p13Dialog>columnKey}"
visible="{p13Dialog>visible}" />
</columnsItems>
</P13nColumnsPanel>
</panels>
</P13nDialog>
</core:FragmentDefinition>
onP13nDialog: function() {
var openAssetTable = this.getView().byId("AssetTable"),
columnHeader = openAssetTable.getColumns();
var openAssetColumns = [];
for (var i = 0; i < columnHeader.length; i++) {
var hText = columnHeader[i].getAggregation("header").getProperty("text");
var columnObject = {};
columnObject.columnKey = hText;
columnObject.visible = columnHeader[i].getBindingContext("columns").
getModel().getProperty(columnHeader[i].getBindingContext(
"columns").getPath()).visible;
openAssetColumns.push(columnObject);
}
var cJSONModel = new sap.ui.model.json.JSONModel({
ColumnCollection: openAssetColumns
});
this.getView().setModel(cJSONModel, "p13Dialog");
var dialog = sap.ui.xmlfragment("p13nDialog.view.p13",
this.getView().getController());
this.getView().addDependent(dialog);
dialog.open();
},
onOK: function(oEvent) {
var data = {
ColumnCollection: oEvent.getParameter("payload").columns.tableItems
};
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData(data);
this.getView().setModel(oJSONModel, "columns");
this.byId("AssetTable").setWidth("100%");
this.columnListItem();
oEvent.getSource().close();
},
onCancel: function(oEvent) {
var data = this.getView().getModel("columns").getData();
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData(data);
this.getView().setModel(oJSONModel);
this.byId("AssetTable").setWidth("100%");
this.columnListItem();
oEvent.getSource().close();
},
onReset: function() {
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.loadData("model/columns.json");
this.getView().setModel(oJSONModel, "p13Dialog");
this.byId("AssetTable").setWidth("100%");
},
columnListItem: function() {
if (this.byId("newRow") !== undefined) {
this.byId("newRow").destroy();
}
this.byId("AssetTable").destroyItems();
var data = this.getView().getModel("columns").getData().ColumnCollection;
var columnlist = [];
var columnObject = {};
columnObject.Column = new sap.m.Text({
text: "ProductID"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Product ID";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "Name"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Name";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "Category"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Category";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "SupplierName"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Supplier Name";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "Description"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Description";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "10"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Weight Measure";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "5"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Weight Unit";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "50"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Price";
columnlist.push(columnObject);
columnObject = {};
columnObject.Column = new sap.m.Text({
text: "Status"
}).addStyleClass("sapUiSizeCompact");
columnObject.coulmnKey = "Status";
columnlist.push(columnObject);
var columns = [];
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < columnlist.length; j++) {
if (data[i].columnKey === columnlist[j].coulmnKey) {
columns.push(columnlist[j]);
}
}
}
var newRow = new sap.m.ColumnListItem(this.createId("newRow"), {
cells: [
columns[0].Column,
columns[1].Column,
columns[2].Column,
columns[3].Column,
columns[4].Column,
columns[5].Column,
columns[6].Column,
columns[7].Column,
columns[8].Column
]
});
this.byId("AssetTable").addItem(newRow);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |