Sort and format calculated date

jolle

Member
I have a list of events and each event occurs on multiple dates. Now I need to calculate the earliest date and store it as the start date of each event. So far it is working.
Now I want to display the list with german date formating sorted by start date.

I have th problem to use this calculated date for sorting when it is formatted as a german date like '23.09.2013'.

Element properties:
Hiddedn: yes
Calc on save only: yes
Ajax calc: no

My calculation is the following:
PHP:
$my_dates = $this->getForm()->getElementData('fab_kurstage___tag', true);
usort($my_dates,function($a,$b) {return $a['date']-$b['date'];});
$date = JFactory::getDate($my_dates[0][date]);
return $date->toFormat('%d.%m.%Y');

But in this case the sort does not work properly because the calc value is stored as a string in the database and the sort performed in SQL.

The sort does work if I format the value in calculation like this:
PHP:
return $date->toFormat('%Y-%m-%d');

But then I cannot display that data nicely to the end-user in my lists. And I couldn't find a way to use the format string based on sprintf.
I was thinking if JavaScript could to the trick, but don't have clue how to do it.
Or if the calc element would be aware of the data type (string, integer, date, ...) it is handling.

I am using Fabrik 3.0.7 on Joomla 2.5.14.

Any suggestions are welcome.
J?rn
 
A "quick and dirty" possibility: two calc elements, one for user display, one for sorting.
 
I have tried to implement this, but run into additional problems since I am using a group by in that list.
You can habe a look at the list here: https://www.hka-sbk.de/kursliste

I would like to sort the list by date within each group.
I have defined an additional field startdate_sort formated as '%Y-%m-%d'. Can I sort by a field that is not included in the list?
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top