Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

event calendar with pagination?


Go to End


6 Posts   2533 Views

Avatar
marcink

Community Member, 89 Posts

26 April 2009 at 10:23pm

hi,

how can i enable pagination for the calendar?

thanks

Avatar
UncleCheese

Forum Moderator, 4102 Posts

28 April 2009 at 1:16am

It's not supported yet, but assuming you have your own Calendar subclass, you can just overload the Events() method.

public function Events( args... )
{
$events = parent::Events(args.. );
$per_page = 10;
if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
return $events->getRange($_REQUEST['start'], $per_page);
}

Avatar
marcink

Community Member, 89 Posts

28 April 2009 at 5:06am

hi unclecheese,

thanks a lot, you're very helpful!

Avatar
marcink

Community Member, 89 Posts

2 May 2009 at 4:01am

can i use

setPageLimits() or setPageLength()

on the $events in the overloading Events()?

because when i tried

public function Events( )
{
$events = parent::Events( );
$per_page = 10;
if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
$events->setPageLimits($_REQUEST['start'], $per_page, $events->Count());
return $events;
}

i got the right paging info, but all of the events at once. when using getRange(), i got the correct number of events, but no paging info...

thanks

Avatar
Digital Punk

Community Member, 51 Posts

12 March 2010 at 3:45am

Hi there

does anybody got correct pagination of dataobjectset with "setPageLimits"? At the moment I have exactly the same problem like "marcink".

Any help please!

Best regards
Digital Punk

Avatar
Gene

Community Member, 41 Posts

21 September 2010 at 9:41am

Edited: 21/09/2010 9:42am

You need to use both getRange and setPageLimits. Just make sure to use setPageLimits after getRange because getRange returns a new dataobjectset.

public function Events($filter = null, $start_date = null, $end_date = null, $default_view = false, $limit = null, $announcement_filter = null) {
		$events = parent::Events($filter, $start_date, $end_date, $default_view, $limit, $announcement_filter);
		
		$perPage = 20;
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
		$start = (int) $_GET['start'];
		$totalSize = $events->Count();
		
		$limitedEvents = $events->getRange($start, $perPage);
		$limitedEvents->setPageLimits($start, $perPage, $totalSize);
		
		return $limitedEvents;
	}