dhtmlxScheduler event order from xml problem

Hi,

I’ve got five events for Monday, one event for every user daily. How can I control the order of events for a day? I want to order events by name, is it possible? I tried in MySQL ORDER By, PHP, XML, but it doesn’t solved it.

Thanks

Someone might respond? :frowning:

Hello,

That’s a good idea but for now events are ordered based on time and then id.

Kind regards,
Ilya

It’s still not possible? I’m trying to edit manually the config files (db_common.php) to change the Order By property but it doesn’t work…

Starting from scheduler 3.5 it possible to define custom sorting orders for timeline view.
As for month view - you can try to redefine default logic of scheduler._time_order, which is currently looks like

scheduler._time_order = function(evs) { evs.sort(function(a, b) { if (a.start_date.valueOf() == b.start_date.valueOf()) { if (a._timed && !b._timed) return 1; if (!a._timed && b._timed) return -1; return a.id > b.id ? 1 : -1; } return a.start_date > b.start_date ? 1 : -1; }); };

It’s possible to sort by name event?

To be rendered correctly, events need to be sorted by date first, after that they can be sorted by any other parameter ( in above code a.id and b.id can be replaced with a.text and b.text )

Ok, I will try it. Thanks! ;D

I try this:

scheduler.time_order = function(evs) { evs.sort(function(a, b) { if (a.start_date.valueOf() == b.start_date.valueOf()) { if (a._timed && !b._timed) return 1; if (!a._timed && b._timed) return -1; return a.text > b.text ? 1 : -1; } return a.start_date > b.start_date ? 1 : -1; }); };

But it doesn’t work :frowning:

With above code, events which have the same starting date will be sorted by event text
Events which have different start-date will be sorted by start-date

Yes, I know it. But when I apply this code on my Scheduler nothing occurs.

For example:

On 25/04 at 09:00h I have 3 events. The text of this are the following:
T1 P2 P1

If I don’t put the sort code on my js file, the events shown like above. If I try to apply the sort code, the events should be shown like:
P1 P2 T1

BUT, no. It shown like:
T1 P2 P1

It seems they are sorted, but just in wrong way, try to change code from

return a.text > b.text ? 1 : -1;

to

return a.text < b.text ? 1 : -1;

If it doesn’t change anything, please post a snippet of xml|json data with test event, for which it doesn’t work.

Sorry, wrong example.

If I have this events:
T2 P1 T2 P2

Nothing change when I apply the sort function. It’s not a problem of way that is sorted.

Here I post you the xml code of the DB query when I reload my Scheduler.

<event id='479' ><start_date><![CDATA[2013-04-26 21:00:00]]></start_date><end_date><![CDATA[2013-04-26 22:00:00]]></end_date><text><![CDATA[T2]]></text><res_detalls><![CDATA[Name1 test1 ; test2 ; test3]]></res_detalls></event> <event id='480' ><start_date><![CDATA[2013-04-26 21:00:00]]></start_date><end_date><![CDATA[2013-04-26 22:00:00]]></end_date><text><![CDATA[P1]]></text><res_detalls><![CDATA[Name1 test1 ; test2 ; test3]]></res_detalls></event> <event id='481' ><start_date><![CDATA[2013-04-26 21:00:00]]></start_date><end_date><![CDATA[2013-04-26 22:00:00]]></end_date><text><![CDATA[P2]]></text><res_detalls><![CDATA[Name1 test1 ; test2 ; test3]]></res_detalls></event> <event id='482' ><start_date><![CDATA[2013-04-26 21:00:00]]></start_date><end_date><![CDATA[2013-04-26 22:00:00]]></end_date><text><![CDATA[T1]]></text><res_detalls><![CDATA[Name1 test1 ; test2 ; test3]]></res_detalls></event>

Please check the attached sample.
While above solution changes order for month view, it is in fact doesn’t change it for the week|day view. In attached sample a bit more complex solution used to affect sorting in all views.
sch_samp_sort.zip (46.4 KB)

I deactivated the month view, then I only copy the second part of your sort function and it works perfect with day and week view.

Thank you so much!! :smiley: :smiley:

It doesn’t work in a month view, scheduler.time_order isn’t executed. How can I set the order of the events in the same day in a month view?

scheduler.time_order = function(evs) { console.log('time_order'); evs.sort(function(a, b) { if (a.start_date.valueOf() == b.start_date.valueOf()) { console.log('='); if (a._timed && !b._timed) return 1; if (!a._timed && b._timed) return -1; return a.text > b.text ? 1 : -1; } console.log('!='); return a.start_date > b.start_date ? 1 : -1; }); };

Solved… scheduler._time_order instead of scheduler.time_order

Altering the events order with scheduler._time_order produces some errors with the positioning and alignation.

Example WITHOUT scheduler._time_order modifications: i.imgur.com/EFfghan.png
Example WITH scheduler._time_order modifications: i.imgur.com/t2IGXEk.png

As you can see in the second example some events aren’t aligned to the top of the day.

Is it possible to fix it?

Thx

The code that aligns events expects that events are already sorted by the date, so it will not work correctly for not sorted-by-date dataset. Unfortunately it can’t be fixed.

Do you have plans to make it easy to order the events without the positioning errors in a future version?