| Issue 379: | Sorting of events seemingly random | |
| 17 people starred this issue and may be notified of changes. | Back to list |
When the events are loaded, it sorts multiple events on the same day by the order they were entered except in Chrome. Chrome sorts the items in odd rows from the bottom and even rows from the top. I have included an example in the attached file along with a Word document with a screen shot in it. Thanks and this is a great plugin. :)
Oct 5, 2010
I have several events that occur at the same time. This sorting results in a tie in Chrome and they appear in different order each time.
Since I order my events by date and time in PHP/mySQL already, I hacked my fullcalendar.js file so that I can set a flag that prevents sorting:
I changed end of function sliceSegs in viewMethods.
From:
return segs.sort(segCmp);
To:
if (this.options.sortEvents !== undefined && this.options.sortEvents === false) {
return segs;
} else {
return segs.sort(segCmp);
}
Now, I can prevent sorting by setting sortEvents flag to false when creating the calendar:
$('#calendar').fullCalendar({
sortEvents: false
});
Don't know if this will work for all day events or month view as I don't use those.
This will only work if you sort your JSON feed by date and time and is probably not an optimal solution for this problem.
Maybe also sorting on id if we encounter a tie when sorting on date would be an idea?
Oct 7, 2010
Issue 653 has been merged into this issue.
Oct 7, 2010
(No comment was entered for this change.)
Summary:
Sorting of events seemingly random
Jan 7, 2011
I also sorted the events by the title's alphabetical order, but unfortunately the events are displayed in a random fashion.
Mar 13, 2011
I have the same issue. Is it going to be fixed soon?
Jan 12, 2012
http://stackoverflow.com/questions/8231902/jquery-fullcalendar-event-sorting I have the exact same problem as described in this thread :-/ Are there any news as to whether or not this can be fixed? :)
Feb 1, 2012
As already mentioned, the problem is with same date. Just add seconds 1 second to each event and they will be sorted as desired.
Nov 6, 2012
I think I may have a solution.
I used it and it worked for a JSON feed.
1. The first thing to do is, as mentionned, to sort the feed by start date.
2. Then I added a specific attribute called "colOrder" to each event and gave it an integer value: 1 for the event I want to appear first, 2 for the second
3. Then I had to hack the fullcalendar.js by changing the function segCmp.
This function initially sorts events unless they start at the same time and have the same duration.
If two events start simultaneously and have the same duration, nothing is done and left to the browser (hence the random results in Chrome).
The original function is:
function segCmp(a, b) {
return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
}
The new function is:
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;
}
It would also have been possible to compare the title of the events, for example, if you want to sort alphabetically the events (then no need to add a colOrder attribute to each event).
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;
}
Hope that helps.
Apr 12, 2013
Hi, I have the same issue, is it going to be any change about this?
Jun 5, 2013
Hi, same issue here. I tried the different solutions described here (except the solution with adding seconds) but without success. Maybe because I use Jarnos FullCallendar Ressourceview version. Maybe someone has a working solution for this? Thanks!
Jun 5, 2013
Hi,
I also been working on the same or similar issue. My issue was that I was pulling Google Calendar XML files and fullcalendar was not organizing all day events alphabetically. After a tun of google-ing I came up with this solution.
Add “my” code after the following (Line 86) in gcal.js
events.push({
<omitted code>
});
“My Code”
events.sort(function(a, b) {
return a.start - b.start || a.title.localeCompare(b.title);
});
This code sorts all day events in alphanumeric order, it works in every browser perfectly except on Google Chrome, and Chromium. I do not know why the code only fails in Google Chrome based browsers, is it an issue with my code, or the browser.
I working on a calendar that is only has events on it form Monday to Friday. What ends up happening is on every Monday I looked at the sorting didn't work properly, also every couple of months a other day besides Monday fails (ex Oct 31, 2012).
I would like the issue in Chrome to be fixed before submitting the change to the code through GitHub. If anyone could help me it would be appreciated.
Side Note: My understanding of java script is primitive at best, I've first started working with java script about a month ago because of this issue, so I may not be able to answer any questions.
“My code” is a variant found on http://stackoverflow.com/questions/12900058/how-can-i-sort-a-javascript-array-of-objects-numerically-and-then-alphabetically
I hope this helps
BvL
Jun 6, 2013
Hi again, finally I tried the solution described in #7 (http://stackoverflow.com/questions/8231902/jquery-fullcalendar-event-sorting). This definately does the trick! I used the code in the marked answer (see link). I use the "event" option of FC to fetch events from a JSON feed. This is described here : http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/ (single-source events option example). I just added a "success" option to the ajax request object and used the code from stackoverflow (altered it for me) to add seconds to the starttime of the events. I do this only if the browser is chrome: if (window.chrome != undefined)... regards Ben
Jun 6, 2013
Hi again, just another hint. Make shure that the workaround with adding seconds does not add too much seconds that it changes your events start seriously. So you should maybe use a count variable to hold the add value under 30 seconds as this will not affect the minutes of your events start time. In my case I have a lot of events in the week view. regards Ben
Aug 13, 2013
this bugfix was released in 1.6.2 i believe. sorts by duration, all-day, time, and then title (alphabetically). If you want further control, Issue 364 deals with that.
Status:
Released
Labels: -Type-Defect Type-BehaviorMod
Jan 25, 2014
I just came across this issue while using Jarnos FullCallendar Ressourceview version, the pre-built version available on the website references version 1.6.1. I did a git pull of the master, which references 1.6.4, and it resolved the issue with sorting. https://github.com/jarnokurlin/fullcalendar I just need to rebuild it using lumbar. Thanks for the great software.
Feb 11, 2015
This works for me https://code.google.com/p/fullcalendar/issues/detail?id=379#c9 I have custimzed the js like this so both functionality old and your customize alos works, add below code function segCmp(a, b) { if (!isNaN(a.event.colOrder) && !isNaN(b.event.colOrder)){ return (a.event.colOrder - b.event.colOrder); } return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start); } also add parameter in your json response. colOrder:1, |
|
| ► Sign in to add a comment |
Labels: Type-Defect