Hi, i am currently trying to build a pagination on a dataobject. The DO belongs to many Pages.
<?php
class Mitarbeiter extends DataObject {
// Contact object's fields
private static $db = array(
'Name' => 'Varchar(255)',
'Vorname' => 'Varchar(255)',
'Beschreibung' => 'Text',
'Webseite' => 'Varchar(255)',
'Telefon' => 'Varchar(255)',
'EMail' => 'Varchar(255)'
);
// One-to-one relationship with profile picture and contact list page
private static $has_one = array(
'ProfilePictures' => 'ProfilePictures_Image'
);
private static $belongs_many_many = array(
'Page' => 'SiteTree'
);
In Page.php it is referenced with
private static $many_many = array(
'Mitarbeiter' => 'Mitarbeiter',
...
In the Page Controller i use
public function PaginatedPages() {
$paginatedList = new AjaxPaginatedList(Mitarbeiter::get(), $this->request);
$paginatedList->setPageLength(2)->where('"PageID" = '.$this->ID.'')->Sort("SortOrder", "ASC");
return $paginatedList;
}
The Dataobjects are linked to the page via
// Start Mitarbeiterzuordnung
$MitarbeiterFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(10),
new GridFieldDeleteAction('unlinkrelation'),
new GridFieldSortableRows('SortOrder'),
new GridFieldManyRelationHandler(), 'GridFieldPaginator'
);
$MitarbeiterField = new GridField("Mitarbeiter", "Mitarbeiter", $this->Mitarbeiter()->sort('SortOrder'), $MitarbeiterFieldConfig);
$fields->addFieldToTab('Root.Mitarbeiter', $MitarbeiterField);
But The PaginatedList now lists all Dataobjects. How can i filter over the Page_Mitarbeiter table to only show those Mitarbeiter that are linked to the current page?
Can anybody help?
Greetings, Carsten.