Hi there,
is there any way to order elements in a gridfield using drag and drop, like the dataobjectmanager plugin used to do?
Friendly regards,
Maurice
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hi there,
is there any way to order elements in a gridfield using drag and drop, like the dataobjectmanager plugin used to do?
Friendly regards,
Maurice
Shameless plug https://github.com/UndefinedOffset/SortableGridField, it actually missed getting merged into the core of SS 3.0
Nice work UndefinedOffset!
Well that certainly makes live more easier, thanks!
Only one question, I think your documentation is good up to the point where you state " If you are using a many_many relationship you will need to do a custom getter to set the sort order of this relationship". How should I interpret this, I don't really have a clue on it.
Thanks in advance,
Maurice
Hmm, it seems that fixSortColumn() causes some trouble here:
$owner = $gridField->Form->getRecord();
$sortColumn = $this->sortColumn;
$i = 1;
$many_many = ($list instanceof ManyManyList);
if ($many_many) {
list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($gridField->getName());
}
this causes the query further on the line to not execute (for the many_many case at least). Does this have something to do with not setting a 'custom getter'? How should I fix that?
Thanks in advance,
Maurice
Temporarely solved this by changing all queries inside if($many_many) { } to
DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $sortPositions[0]
. ' WHERE "' . $this->componentField . '" = ' . $targetItem->ID . ' AND "' . $this->parentField . '" = ' . $owner->ID);
and putting the following statics in the class
public $table;
public $componentField;
public $parentField;
And naming them in the definition of the GridFieldSortableRows (inside the getCMSFields()):
$config = GridFieldConfig_RelationEditor::create();
$config->addComponent($sort = new GridFieldSortableRows('SortOrder'));
$sort->table = 'ProductHolder_Products';
$sort->parentField = 'ProductHolderID';
$sort->componentField = 'ProductID';
Well, that's it for now, I hope someone else may also find this useful. Also, I don't know i this is a nice way to do this and therefor I'm still interested in a possibly better, more clean way to achieve this.
Friendly regards,
Maurice
Can you post your code that defines the many_many relationship? As well as the line (or lines) you use to create the grid field instance? In my testing many_many relationships seem to work fine.
Hi, this is the definition:
class Product:
static $belongs_many_many = array(
'ProductHolder' => 'ProductHolder'
);
class ProductHolder:
static $many_many = array(
'Products' => 'Product'
);
static $many_many_extraFields = array(
'Products' => array(
'Volgorde' => 'Int'
)
);
$productList = $this->Products();
$productList->sort('Volgorde');
$config = GridFieldConfig_RelationEditor::create();
$row = "Volgorde";
$config->addComponent($sort = new GridFieldSortableRows(stripslashes($row)));
$sort->table = 'ProductHolder_Products';
$sort->parentField = 'ProductHolderID';
$sort->componentField = 'ProductID';
$productfield = new GridField("Product", "Producten op deze pagina", $productList, $config);
$fields->addFieldToTab('Root.Product', $productfield);
return $fields;
Hope this is enough information, wondering if you spot what went wrong.
Friendly regards,
Maurice