Jump to:

10998 Posts in 2732 Topics by 1822 members

All other Modules

SilverStripe Forums » All other Modules » event calendar with pagination?

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1995 Views
  • marcink
    Avatar
    Community Member
    89 Posts

    event calendar with pagination? Link to this post

    hi,

    how can i enable pagination for the calendar?

    thanks

  • UncleCheese
    Avatar
    4085 Posts

    Re: event calendar with pagination? Link to this post

    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);
    }

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: event calendar with pagination? Link to this post

    hi unclecheese,

    thanks a lot, you're very helpful!

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: event calendar with pagination? Link to this post

    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

  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    Re: event calendar with pagination? Link to this post

    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

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: event calendar with pagination? Link to this post

    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;
       }

    1995 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.