This is a migrated thread and some comments may be shown as answers.

Show week number in custom view

5 Answers 337 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 2
Igor asked on 29 Oct 2013, 08:02 PM
Hi!

i am creating a custom schedule view like that:

var SchedulerWeekView = kendo.ui.MultiDayView.extend({
          options: {
              selectedDateFormat: "{0:D} - {1:D}"
          },
          nextDate: function () {
              var startDate = this.startDate();
              return new Date(startDate.setDate(startDate.getDate() + 7));
          },
          previousDate: function () {
              var endDate = this.endDate();
              return new Date(endDate.setDate(endDate.getDate() - 7));
          },
          name: "SchedulerWeekView",
          calculateDateRange: function () {
 
              var selectedDate = this.options.date,
                  start = kendo.date.dayOfWeek(selectedDate, this.calendarInfo().firstDay, -1),
                  idx, length,
                  dates = [];
 
              for (idx = 0, length = 7; idx < length; idx++) {
                  if (start.getDay() <= 5 && start.getDay() > 0) {
                      dates.push(start);
                  }
                  start = kendo.date.nextDay(start);
              }
 
              this._render(dates);
          }
 
      });
I would like to show the week number on selectedDateFormat. Right now it shows: {week start date} - {week end date}.
Is that possible to change format to show the week number?

Thanks!

5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 30 Oct 2013, 11:55 AM
Hello Igor,

You can take full control over the text in question by overriding the dateForTitle method and returning the desired string.

var SchedulerWeekView = kendo.ui.MultiDayView.extend({ 
  dateForTitle: function() {
    return  "My custom text"
  },
 //...
});

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Igor
Top achievements
Rank 2
answered on 01 Nov 2013, 07:01 AM
Hi Rosen, thank you for your answer.
I am not sure, but in the example you provided it is not possible to retrieve current selected week number.
I need to have week number to display it in dateForTitle. E.g.:

var SchedulerWeekView = kendo.ui.MultiDayView.extend({
  dateForTitle: function() {
    var weekNumber = 1;     //TODO: how do I retrieve the real week number here?
    return "Week: "+weekNumber;
  },
 //...
});
Thanks in advance!
0
Igor
Top achievements
Rank 2
answered on 01 Nov 2013, 07:15 AM
the only idea coming - is to calculate the week number inside the navigation functions (previousDate and nextDate) and put it to a global variable:


var weekNumber = 0;
 
//week number of date calculation from here:
//http://stackoverflow.com/questions/7765767/show-week-number-with-javascript
Date.prototype.getWeek = function() {
        var onejan = new Date(this.getFullYear(),0,1);
        return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
    }
 
var SchedulerWeekView = kendo.ui.MultiDayView.extend({
 
          nextDate: function () {
              var startDate = this.startDate();
              var navigatedDate = new Date(startDate.setDate(startDate.getDate() + 7));
               
               //Store week number
               weekNumber = navigatedDate.getWeek();
 
               return navigatedDate;
          },
           
          previousDate: function () {
              var endDate = this.endDate();
               
              var navigatedDate = new Date(endDate.setDate(endDate.getDate() - 7));
               
              //Store week number
               weekNumber = navigatedDate.getWeek();
 
               return navigatedDate;
          },
  
         dateForTitle: function() {
             
            //return previously stored week number
          
            return "Week: " + weekNumber;
          },
  
        //...... other configuration settings
  
      });
I have not tested this example yet.
I am really doubt that is good idea, since we are using global variable but not the real data binding/formatting.
In addition, it is a View prototype, that might be reusable, therefore global variables might be overwritten.


0
Accepted
Rosen
Telerik team
answered on 01 Nov 2013, 08:36 AM
Hi Igor,

As the dateForTitle is part of the SchedulerWeekView  class, you do have access to other members. Thus, you could use the startDate value to calculate the week number within the dateForTitle function. For example:

dateForTitle: function() {
  return "Week " + kendo.recurrence.weekInYear(this.startDate(), this.calendarInfo().firstDay);
}


Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Igor
Top achievements
Rank 2
answered on 01 Nov 2013, 09:07 AM
Hi Rosen
Thanks for quick answer. I just tried and it works for me!
Tags
Scheduler
Asked by
Igor
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Igor
Top achievements
Rank 2
Share this question
or