Rearranging grouped list by date

webstar

Member
I’m not sure if the title explains what I’m trying to do. I have a list of events and each event is assigned to a day of the week with a drop down. Eg Monday Tuesday etc.
In my list I am then grouping them by the day eg all the Monday events are grouped together then all the Tuesday events. What I want to do is show grouped but I want the Current day to be at the top of the list. Eg
Tuesday, Wednesday Thursday Friday Saturday Sunday Monday

so what ever day it is will be the first group in the list. I have no idea of where to even start.

See the timetable at pranayogastudio.co.uk for what I’m trying to achieve
 
You would probably need a PHP-events plugin on the list running OnPreloadData which updates an extra column used for ordering. This updates the column every time the list is opened and before the data is displayed. So as of today, the Friday events would have a field value "1", Saturday "2" etc.
 
Thanks juuser. sorry for the late reply. I forgot I had posted this. I'll look into this. but probably needs more coding skills than I'm capable of.
 
Hm, Ive managed to do this in Onloaddata - But for some reason The $data is not being overwritten with the new order - Can anyone help?

// $model is the list model, we want to get its data and then alter it.
$data = $model->getData();
$data_start = array_slice($data, 1);
$data_end= array_slice($data, 0,7);
$datamerge =array_merge($data_start, $data_end);

foreach ($datamerge as $group)
{
echo '<pre>';
print_r($group);
echo '</pre>';


foreach ($group as $row)
{

}
}
 
Actually Ive figured it out. on the list front end template. I simply split the main Grouped array into 2. EG there are 7 days so I used the array split to split the array based on whatever day it was - I then re-merged the 2 arrays together.
 
My initial thought was to update the extra field with numbers on list load and then order by that element, but your solution is really neat.

Would'nt be a bad idea to share the code here in case anyone else bumps into similar challenge in the future.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top