21278 Posts in 5728 Topics by 2599 members
| Go to End | Next > | |
| Author | Topic: | 1243 Views |
-
Drag and drop order of Gridfield elements

10 July 2012 at 3:10am
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 -
Re: Drag and drop order of Gridfield elements

10 July 2012 at 11:13am
Shameless plug https://github.com/UndefinedOffset/SortableGridField, it actually missed getting merged into the core of SS 3.0
-
Re: Drag and drop order of Gridfield elements

10 July 2012 at 10:55pm
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 -
Re: Drag and drop order of Gridfield elements

11 July 2012 at 1:06am
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 -
Re: Drag and drop order of Gridfield elements

11 July 2012 at 1:29am
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 -
Re: Drag and drop order of Gridfield elements

11 July 2012 at 2:30am Last edited: 11 July 2012 2:37am
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.
-
Re: Drag and drop order of Gridfield elements

11 July 2012 at 2:35am
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
| 1243 Views | ||
| Go to Top | Next > |



