initDataModel: function () {
var oModel = this.getModel(),
fnAfterMetadataLoaded = function () {
var aSets = [];
var oMetaData = oModel.getServiceMetadata();
for (var j = 0; j < oMetaData.dataServices.schema.length; j++) {
var oEntityContainer = oMetaData.dataServices.schema[j].entityContainer;
if (oEntityContainer) {
var aEntityContainer = oEntityContainer[0];
if (aEntityContainer && aEntityContainer.entitySet.length > 0) {
for (var i = 0; i < aEntityContainer.entitySet.length; i++) {
aSets.push({
SetName: aEntityContainer.entitySet[i].name,
EntityName: aEntityContainer.entitySet[i].entityType
});
}
var oData = {
DataSet: aSets
};
//Creation of the JSON Model for the Test Daya
var oDataModel = new sap.ui.model.json.JSONModel(oData);
this.setModel(oDataModel, "DataModel");
return;
}
}
}
}.bind(this);
oModel.metadataLoaded().then(fnAfterMetadataLoaded);
},
_onObjectMatched: function (oEvent) {
var sSetName = oEvent.getParameter("arguments").SetName,
sEntityName = oEvent.getParameter("arguments").EntityName;
this.getModel("appView").setProperty("/layout", "TwoColumnsMidExpanded");
var oModel = this.getModel();
oModel.metadataLoaded().then(function () {
oModel = this.getModel();
oModel.setUseBatch(false);
oModel.read("/" + sSetName, {
success: function (oData, oResponse) {
var oItems = {
DataSet: oData.results
};
this.getModel("DataModel").setData(oItems);
this.createSmartTable(sEntityName, sSetName);
}.bind(this)
});
}.bind(this));
},
_extractEntity: function (sEntityName) {
var aRes = sEntityName.split("."),
sNamespace = aRes[0],
sEntity = aRes[1],
oEntity,
oModel = this.getModel(),
oMetaData = oModel.getServiceMetadata();
for (var j = 0; j < oMetaData.dataServices.schema.length; j++) {
if (oMetaData.dataServices.schema[j].namespace === sNamespace) {
var aEntities = oMetaData.dataServices.schema[j].entityType;
for (var i = 0; i < aEntities.length; i++) {
if (aEntities[i].name === sEntity) {
oEntity = aEntities[i];
break;
}
}
break;
}
}
return oEntity;
},
createSmartTable: function (sEntityName, sSetName) {
var oEntity = this._extractEntity(sEntityName);
if (oEntity) {
var aCells = [];
for (var i = 0; i < oEntity.property.length; i++) {
var oCol = oEntity.property[i];
aCells.push(oCol.name);
}
if (aCells.length > 0) {
var sFields = "",
sCols = "",
sCels = "";
for (i = 0; i < aCells.length; i++) {
sFields += aCells[i];
if (i < aCells.length - 1) {
sFields += ",";
}
sCols += "" +
" <m:Column visible='true'> \n" +
" <m:customData> \n" +
" <core:CustomData key='p13nData' \n" +
" value='\\{\"sortProperty\":\"" + aCells[i] + "\",\"filterProperty\":\"" + aCells[i] + "\",\"columnKey\":\"" +
aCells[i] + "\",\"leadingProperty\":\"" + aCells[i] + "\",\"columnIndex\":\"" + i + "\"}'/> \n" +
" </m:customData> \n" +
" <m:Text text='" + aCells[i] + "'/> \n" +
" </m:Column> \n";
sCels += "" +
" <m:Text text=\"{path:'DataModel>" + aCells[i] + "'}\"/> \n";
}
var oViewModel = this.getModel("detailView");
oViewModel.setProperty("/setItems", sSetName);
var xmlStr = "" +
"<core:FragmentDefinition xmlns:m='sap.m' xmlns:smartTable='sap.ui.comp.smarttable' xmlns:core='sap.ui.core'> \n" +
" <smartTable:SmartTable id='__smartTable' entitySet='DataSet' tableBindingPath='DataModel>/DataSet' header='{detailView>/setItems}' \n" +
" showRowCount='true' tableType='ResponsiveTable' showFullScreenButton='false' useVariantManagement='false' enableAutoBinding='true' \n" +
" requestAtLeastFields='" + sFields + "' \n" +
" useExportToExcel='false' ignoredFields='' beforeRebindTable='handleBeforeRebindTable'> \n" +
" <m:Table mode='MultiSelect' busy='{detailView>/tableSectionTypeBusy}'> \n" +
" <m:columns> \n" +
sCols +
" </m:columns> \n" +
" <m:items> \n" +
" <m:ColumnListItem type='Inactive' press='onTableItemPress'> \n" +
" <m:cells> \n" +
sCels +
" </m:cells> \n" +
" </m:ColumnListItem> \n" +
" </m:items> \n" +
" </m:Table> \n" +
" </smartTable:SmartTable> \n" +
"</core:FragmentDefinition> \n";
var oLayout = this.getView().byId("myLayout");
var aControls = oLayout.removeAllContent();
for (var j = 0; j < aControls.length; j++) {
var oControl = aControls[j];
if (typeof oControl.destroy === "function") {
oControl.destroy();
}
}
sap.ui.core.Fragment.load({
type: "XML",
id: sSetName,
definition: xmlStr,
controller: this
}).then(function (oControll) {
oLayout.addContent(oControll);
});
}
}
},
createTable: function (sEntityName) {
var oTable = new sap.m.Table(),
oEntity = this._extractEntity(sEntityName);
if (oEntity) {
oTable.removeAllColumns();
oTable.unbindItems();
var aCells = [];
for (var i = 0; i < oEntity.property.length; i++) {
var oCol = oEntity.property[i];
var oColumn = new sap.m.Column({
header: new sap.m.Label({
text: oCol.name
})
});
oColumn.addCustomData(
new sap.ui.core.CustomData({
key: "p13nData",
value: "\{'sortProperty': '" + oCol.name + "', 'filterProperty': '" + oCol.name + "', 'columnKey': '" + oCol.name +
"', 'leadingProperty': '" + oCol.name + "', 'columnIndex':'" + i + "'}"
}));
aCells.push(new sap.m.Text({
text: "{DataModel>" + oCol.name + "}"
}));
oTable.addColumn(oColumn);
}
oTable.bindItems({
path: "DataModel>/DataSet",
template: new sap.m.ColumnListItem({
cells: aCells
})
});
}
return oTable;
},
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 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |