There are no secrets to success. It is the result of preparation, hard work, and learning from failure.

Thursday 30 June 2016

Months display

Click here and follow my SAP UI5/FIORI snippets and information Page
I have done this example with list control. It takes current Date from system and calculate then set in the list.It shows current with previous three months only.Go through it and please let me know in case of any issue/doubt.


Paste below lines in View
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="set_month.S1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:vikas="sap.ui.layout">
<Page title="Set Month">
<content>
<vikas:Grid defaultSpan="L12 M12 S12">
<List items="{/results}" id="ListId" mode="SingleSelectMaster" select="listSelect">
<StandardListItem title="{month}">
</StandardListItem>
<layoutData>
<vikas:GridData span="L4 M4 S4">
</vikas:GridData>
</layoutData>
</List>
</vikas:Grid>
</content>
</Page>
</core:View>

Paste below lines in Controller

//write in onInit()
var months = [ "January", "February", "March", "April", "May", "June",
"July", "August", "Sept", "October", "November", "December" ];
var currentDate = new Date();
var month = currentDate.getMonth();
var year = currentDate.getFullYear();
var monthArr = [];
for (var i = month; i > month - 4; i--) {
if (i === -1) {
monthArr.push({
"month" : months[11],
"Year" : year
});
} else if (i === -2) {
monthArr.push({
"month" : months[10],
"Year" : year
});
} else if (i === -3) {
monthArr.push({
"month" : months[9],
"Year" : year
});
} else {
monthArr.push({
"month" : months[i],
"Year" : year
});
}
}
var json = new sap.ui.model.json.JSONModel({
"results" : monthArr
});
this.byId("ListId").setModel(json);

Result



2 comments: