Balaji
Balaji

Reputation: 35

dijit calendar to display only 52 weeks back from current day in dojo

I have a requirement of showing calendar to only 52 weeks back from current day in dojo ,I'm using dijit/Calendar for the same,can some one help me by providing light on displaying only 52 weeks back from current day in dijit calendar.

currently I am using data-dojo-props which is disabling only weekends in calendar .

<div id="mycal" data-dojo-attachpoint="mycal" 
                data-dojo-type="dijit.calendar" 
                data-dojo-props="isDisabledDate:dojo.date.locale.isWeekend">
</div>

Upvotes: 1

Views: 252

Answers (1)

Bourbia Brahim
Bourbia Brahim

Reputation: 14702

This is so simple , you have to do it in programmatic manner ,

Create a calendar dijit , then overide its isDisabledDate function by checking both show cal view days are > or are week days : as below

return dojoDate.difference(date, new Date(), "day") > disable_before_days || locale.isWeekend(date)  ;

See below working snippet :

require(["dojo/parser",
    "dijit/Calendar",
    "dijit/registry",
    "dojo/date",
    "dojo/date/locale",
    "dojo/ready",
    "dojo/domReady!"
], function(parser, Calendar, registry, dojoDate, locale, ready){

    disable_before_days = 52;

    ready(function(){
      //var calendar = registry.byId("mycal");
      var calendar = new Calendar({
        value: new Date(),
        isDisabledDate:function(date, localString){
          return dojoDate.difference(date, new Date(), "day") > disable_before_days 
              || locale.isWeekend(date) 
              || date > new Date() ;
        }
       }, "mycal");
    });
});
html, body {
    height: 100%;
    padding: 0;	
    margin: 0;
    font-family: Lucida Sans,Lucida Grande,Arial !important;
    font-size: 13px !important;
    background: white;
    color: #333;
}

#mycal .dijitCalendarDisabledDate {
    background-color: #333;
    text-decoration: none;
}

#mycal .dijitCalendarContainer {
    margin: 25px auto;
}
<link href="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojox/calendar/themes/claro/Calendar.css" rel="stylesheet"/>
<link href="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" rel="stylesheet"/>

<script type="text/javascript">
  dojoConfig = {
    isDebug: true,
    async: true,
    parseOnLoad: true
  }
</script>

<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<body class="claro">
  <div id="mycal" ></div>

</body>

Upvotes: 1

Related Questions