schedule-x / schedule-x

JavaScript event calendar. Modern alternative to fullcalendar and react-big-calendar.
https://schedule-x.dev
MIT License
1.02k stars 70 forks source link

Custom sort items in month grid view #548

Open mariela-plaza opened 1 month ago

mariela-plaza commented 1 month ago

Hello again! I've continued exploring this library and I like the what I've been able to implement with all the features it offers, thank you very much once again.

I have one last question for which I haven't been able to find an answer in the docs. I would like to sort the events in my monthsGridView by a parameter different than the start and end date of my events. I haven't seen if it's possible to add an order param in the events to let the calendar know which events to render first in each day or if there is a method in the eventsServicePlugin to reorder the events of the calendar so that the UI displays it in the order I set them out to be.

If someone knows how to achieve this please let me know :) thank you and have a nice day!

tomosterlund commented 1 month ago

Thanks for the appreciation!

Unfortunately, I believe sorting within each day will be quite hard to achieve the way things are built. Due to the way multi-day events are displayed, the order in which events appear is tightly coupled to the month-grid creation algorithm, and only loosely coupled to their current sorting. So building a day-by-day sorting would be very time consuming to the point that I currently can't see myself building it.

I could, however, add an option like monthGridOptions.sortEvents, where you can sort the entire list of events, before they go into the month-creation function. Would that help you?

mariela-plaza commented 1 month ago

Hello there!

Thank you so much for the answer and sorry for taking so long to answer back. If I understand correctly the idea would be to add an additional property on the calendar config object under the monthGridOptions prop. This new property would be the sortsEvent handler which would be a function that I could use to manually sort the events myself and then the events would appear on the UI with the order I set? If that's the case I think that would work perfectly for my use case, thank you very much!

Have a great day and thank you for your amazing work in the community :)