开发者

Viewing events in FullCalendar ordered by event ID instead of start timestamp

I have a calendar set up and when viewing the month view I want to display the events which have been created by their ID and not the time they are due to start.

Is this possible? And if so,开发者_如何学JAVA how would I go about changing the code to display the events in this manner?


Great solution! I've used it and adapted it for my needs. I'm using JSON feeds.

Important: the first condition is to make sure all the events are sorted by start date.

Then, if you want to sort by title :

function segCmp(a, b) {
   var tryCmp = (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
   if (tryCmp == 0) {
            return (a.event.title.toLowerCase() >= b.event.title.toLowerCase()) ? 1: 0;
    }
   return tryCmp;
}

I've also used it another way. I've added a custom attribute to each event of the JSON feed called 'colOrder'(it could be anything) and gave it integer values (1,2,3...). 1 is for the first event I want to see, 2 for the second...

Then I customized the function to use the colOrder attribute to sort the events.

function segCmp(a, b) {
   var tryCmp = (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
   if (tryCmp == 0) {
    if (!isNaN(a.event.colOrder) && !isNaN(b.event.colOrder))
            return (a.event.colOrder - b.event.colOrder);
    }
   return tryCmp;
}


Add ORDER BY id ASC to your query.


no easy way to do this yet, but when this issue is implemented, should be easy: http://code.google.com/p/fullcalendar/issues/detail?id=364


Long time since last post, but just in case someone need it (like me):

change in fullcalendar.js

function segCmp(a, b) {
    return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
}

to

function segCmp(a, b) {
   var tryCmp = (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
   if (tryCmp == 0)
      return (a.event.id - b.event.id);
   return tryCmp;
}

it worked for me

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜