Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

GridFieldConfig_RelationEditor


Reply


5 Posts   1914 Views

Avatar
joelg

Community Member, 129 Posts

11 May 2012 at 10:16pm

Edited: 11/05/2012 10:17pm

Hi there

I'm having some fun with the gridfield in SS3 beta2. I can't really figure out how the many_many relations work with GridField. Here's my code:

public static $many_many = array(

"RightColumnBoxes" => 'RightColumnBox'

);

...

$gridFieldConfig = GridFieldConfig_RelationEditor::create();

$gridFieldConfig->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields('Title');

$GridField = new GridField("RightColumnBoxes", "Context in right column:", $this->RightColumnBoxes(), $gridFieldConfig);

$fields->addFieldToTab("Root.RightColumn", $GridField);

There are no errors with this, but how can I attach these many many relations to my pages where the relation is defined? There are no check boxes in the gridfield, and the search field doesn't seem to return anything.

Is it because this part of gridfield isn't finished?

Many regards

Joel

Avatar
joelg

Community Member, 129 Posts

11 May 2012 at 10:50pm

Ok, figured this one out...

You have to create an array of strings of fieldnames to the setSearchFields method...

It would have been nice though with a possibility to just view all records and select between these (how would I od that?).

Anyway, it works now. The code should look like this:

$gridFieldConfig->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array('Title'));

Avatar
Bolixe

Community Member, 17 Posts

5 June 2012 at 10:06pm

Hi Joelg!

I am also having some fun with the beta 3. You said there is not checkboxes for the dataobjects related with other dataobjects which are in the tabs. Do you know some way to handle the relationships in the way you could do with the complextablefield ????

I would like to have something like this for a project I want to upgrade.

Thanks, greetings

Avatar
spierala

Community Member, 80 Posts

31 July 2012 at 11:38am

Edited: 31/07/2012 11:41am

Hello all,
I also try to figure out how to setup the GridField for a Many-to-many relation. I can´t see checkboxes. You can browse existing DataObjects within a searchfield... and then say "Link Existing". is that the way to go?!
greetz,
Florian

Avatar
hallecsyz

Community Member, 5 Posts

2 August 2012 at 2:39am

Edited: 02/08/2012 7:54am

Hello,

I'm having the same problem as spierala. The DataObjects list only allows me to add, edit or delete items. But how can I edit the relation?

Thanks!

Edit: I just found that the right way is through the filter field, I didn't realize that my problem was that the filter wasn't working. When I start typing I get a javascript error.

SyntaxError: JSON.parse: unexpected character.
In assets/_combinedfiles/lib.js at line 2586

Is there any solution to this problem? What am I doing wrong?