Closed AlphaCactus closed 11 years ago
What version of SilverStripe are you using? As well have you tried eliminating GridFieldManyRelationHandler see if that solves the issue? Also what does your model look like (the dataobject and the page type)? And the implementation code for the gridfield, for the model simplified versions are fine i.e just the getCMSFields and relationship definition on the dataobject. For the managed object just the database statics at the top are really all I need.
Also in looking at the module you're referencing it maybe the case that GridFieldSortableRows may not work with this type of list. I'll need to do some experimenting, but please do provide the information I asked for in the previous post. It will help me narrow things down, and could lead me to discovering the issue may not be related to this module at all. Hard to say :)
Silverstripe 3.1 master Removing either module allows both modules to work just fine. SortableGridField works fine regardless. It is only when clicking the "Change Relation Status" button provided by GridFieldManyRelationHandler that there is a problem because, it seems, that GridFieldManyRelationHandler is likely [incorrectly] modifying the list and then passing it to GridFieldSortableRows.
here is relevant code:
class BiographiesPage extends Page {
private static $many_many = array(
'Biographies' => 'Biography'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$gf = GridField::create( 'Biographies', 'Biographies', $this->Biographies(), GridFieldConfig_RelationEditor::create() );
$config = $gf->getConfig();
$config->addComponent( new GridFieldSortableRows('SortOrder') );
// @TODO: Can't use GridFieldManyRelationHandler with GridFeidlSortableRows beacuse GridFieldSortableRows breaks GridFieldManyRelationHandler (though the bug may be in GridFieldManyRelationHandler)
//$config->addComponent( new GridFieldManyRelationHandler(), 'GridFieldPaginator' );
$fields->addFieldToTab( 'Root.Biographies', $gf );
CMSutils::addGridFieldManyRelationHandlerWarning( $fields, "Biographies");
return $fields;
}
// Sorting Support
private static $many_many_extraFields = array(
'Biographies' => array( 'SortOrder' => 'Int' )
);
public function Biographies() {
return $this->getManyManyComponents('Biographies')->sort('SortOrder');
}
I just had a flash of genius and modified addComponent to force GridFieldSortableRows to go before GridFieldManyRelationHandler. This seems to be working. You might add a note to the readme.
$config->addComponent( new GridFieldManyRelationHandler(), 'GridFieldPaginator' );
// GridFieldSortableRows must be set to go before GridFieldManyRelationHandler
$config->addComponent( new GridFieldSortableRows('SortOrder'), 'GridFieldManyRelationHandler' );
Sweet thanks, I will definitely do that.
Thanks for your help. As far as I'm concerned you may close this issue.
I'll leave it for now so I'll remember to update the readme lol
When using the GridFieldManyRelationHandler module https://github.com/simonwelsh/silverstripe-GridFieldRelationHandler on the same GridField, GridFieldSortableRows::fixSortColumn breaks on line 134.
ERROR [User Error]: Sort column SortOrder could not be found in Biography's ancestry.
The problem is occuring because the list being passed in is a DataList and not a ManyManyList, even though it Should be a ManyManyList.
I"m not really sure if this is a problem in SortableGridField or in GridFieldManyRelationHandler, but the error is occuring in code in SortableGridField so I thought I'd start here.
Relevant Code:
Error Report