.
.
.
.
return BaseController.extend("controller.Main", {
_mSortFieldsVehicle: {
name: ["vehicleName",true],
value: ["vehicleValue",false],
timestamp: ["vehicleTimeStamp",false]
},
_mSortFieldsCost: {
name: ["costName",true],
price: ["costPrice",false],
timestamp: ["costTimeStamp",false]
},
.
.
.
.
}
.
.
.
onInit: function() {
this._oVSD = null; // Store the dialog object
this._sSortField = null; // Store the sorted Field
this._bSortDescending = false; // preset the sort direction
this._aValidSortFields = ["name", "value", "timestamp"]; // which fields are valid or search
this._aValidSortFieldsCost = ["name", "price", "timestamp"]; // which fields are valid or search
this._sTableSort = "idVehicle"; // Preset table Vehicle // which table is to sort
this._initViewSettingsDialog(); // initial the dialog
this._oTable = this.byId("tableVehicle"); // Table Vehicle
this._oTableCost = this.byId("tableListCost"); // Table Cost
.
.
.
}
.
.
.
onSortButtonPressed: function(oEvent) {
var oRouter = this.getRouter();
this._oRouterArgs.query.showDialog = 1;
this._sTableSort= oEvent.getParameter("id"); // Store the called controler ID
this._setOrderItems();
oRouter.navTo("main", this._oRouterArgs);
},
.
.
.
_isTableVehicle: function() {
return (this._sTableSort.indexOf("idVehicle") > -1);
},
_isSordFieldValid: function(sSortField) {
if (this._isTableVehicle()) {
if (this._aValidSortFields.indexOf(sSortField) > -1) {
return true;
}
} else {
if (this._aValidSortFieldsCost.indexOf(sSortField) > -1) {
return true;
}
}
return false;
},
_setOrderItems: function() {
var oResourceBundle = this.getResourceBundle();
this._oVSD.removeAllSortItems(); // remove items
// which fields should be sort
var _mSorter = this._isTableVehicle() ? this._mSortFieldsVehicle : this._mSortFieldsCost;
var _loVSD = this._oVSD;
jQuery.each(_mSorter, function(sSortKey, oText) {
_loVSD.addSortItem(new sap.m.ViewSettingsItem({
key: sSortKey,
text: oResourceBundle.getText(oText[0]),
selected: oText[1]
}));
});
},
.
.
_initViewSettingsDialog: function() {
var oRouter = this.getRouter();
this._oVSD = new sap.m.ViewSettingsDialog("vsd", {
confirm: function(oEvent) {
var oSortItem = oEvent.getParameter("sortItem");
this._oRouterArgs.query.sortField = oSortItem.getKey();
this._oRouterArgs.query.sortDescending = oEvent.getParameter("sortDescending");
delete this._oRouterArgs.query.showDialog;
oRouter.navTo("main", this._oRouterArgs, true /*without history*/ );
}.bind(this),
cancel: function(oEvent) {
delete this._oRouterArgs.query.showDialog;
oRouter.navTo("main", this._oRouterArgs, true /*without history*/ );
}.bind(this)
});
this._setOrderItems(); // Set the sort Items
},
.
.
.
.
.
.
"routes": [
{
"pattern": "Policies/{objectId}:?query:",
"name": "main",
"target": [
"main"
]
},
.
.
]
*
* Applies sorting on our table control.
* @param {string} sSortField the name of the field used for sorting
* @param {string} sortDescending true or false as a string or boolean value to specify a descending sorting
* @private
*/
_applySorter: function(sSortField, sortDescending) {
var bSortDescending, oBinding, oSorter;
// only continue if we have a valid sort field
if (sSortField && this._isSordFieldValid(sSortField)) {
// convert the sort order to a boolean value
if (typeof sortDescending === "string") {
bSortDescending = sortDescending === "true";
} else if (typeof sortDescending === "boolean") {
bSortDescending = sortDescending;
} else {
bSortDescending = false;
}
// sort only if the sorter has changed
if (this._sSortField && this._sSortField === sSortField && this._bSortDescending === bSortDescending) {
return;
}
this._sSortField = sSortField;
this._bSortDescending = bSortDescending;
oSorter = new Sorter(sSortField, bSortDescending);
// sync with View Settings Dialog
this._syncViewSettingsDialogSorter(sSortField, bSortDescending);
// Sorting depending on which table is select
if ( this._isTableVehicle() ) {
oBinding = this._oTable.getBinding("items");
} else {
oBinding = this._oTableCost.getBinding("items");
}
oBinding.sort(oSorter);
}
},
onInit: function() {
.
.
var oRouter = this.getRouter();
oRouter.getRoute("main").attachPatternMatched(this._onObjectMatched, this);
}
_onObjectMatched: function(oEvent) {
this._oRouterArgs = oEvent.getParameter("arguments");
this._oRouterArgs.query = this._oRouterArgs["?query"] || {};
if (this._oRouterArgs.query) {
// search/filter via URL hash
//this._applySearchFilter(this._oRouterArgs.query.search);
// sorting via URL hash
this._applySorter(this._oRouterArgs.query.sortField, this._oRouterArgs.query.sortDescending);
// show dialog via url hash
if (this._oRouterArgs.query.showDialog === "1") {
this._oVSD.open();
}
}
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
11 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |