smindel / silverstripe-gridfieldeditablemanymanyextracolumns Goto Github PK
View Code? Open in Web Editor NEWadds form fields to the Silverstripe GridField to edit DataObject::$many_many_extraFields
adds form fields to the Silverstripe GridField to edit DataObject::$many_many_extraFields
Hi Andreas,
storing extra fields doesn't work (with autosave on or off).
Look at my code:
class Billboard extends DataObject {
static $db = array (
'Cislo' => 'Varchar(127)',
'Popis' => 'Text'
);
static $has_one = array(
'Foto' => 'Image'
);
static $many_many = array (
'Objednavky' => 'Objednavka',
);
static $many_many_extraFields = array(
'Objednavky' => array(
'StartDate' => 'Varchar',
'EndDate' => 'Varchar'
),
);
static $searchable_fields = array(
"Cislo"
);
static $summary_fields = array(
'Cislo'
);
static $description = 'Zoznam billboardov';
function getCMSFields() {
$fields = parent::getCMSFields();
if ($this->ID) {
// add my custom formfield for subprojects
$config = GridFieldConfig_RelationEditor::create();
$config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array('Cislo'))->setResultsFormat('$Cislo');
$gridField = new GridField("Objednavky", "Objednavky", $this->Objednavky(), $config);
$fields->addFieldToTab("Root.Objednavky", $gridField);
$component = new GridFieldEditableManyManyExtraColumns();
$component->setSaveAutomatically(false);
$fields->dataFieldByName('Objednavky')->getConfig()->addComponent($component, 'GridFieldEditButton');
//$fields->addFieldToTab("Root.Extra", new TextField('ManyMany[StartDate]', 'Start'));
} else {
$fields->addFieldToTab("Root.Objednavky", new LiteralField("objnote","Objednavku pridáte po prvom uložení"));
}
return $fields;
}
}
and
class Objednavka extends DataObject {
static $db = array (
'Cislo' => 'Varchar(127)',
'Popis' => 'Text'
);
static $has_one = array(
'Zakaznik' => 'Zakaznik'
);
static $belongs_many_many = array (
'Billboardy' => 'Billboard',
);
static $searchable_fields = array(
"Cislo"
);
static $summary_fields = array(
'Cislo'
);
function getCMSFields() {
$fields = parent::getCMSFields();
if ($this->ID) {
// add my custom formfield for subprojects
$config = GridFieldConfig_RelationEditor::create();
$config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array('Cislo'))->setResultsFormat('$Cislo');
$gridField = new GridField("Billboardy", "Billboardy", $this->Billboardy(), $config);
$fields->addFieldToTab("Root.Billboardy", $gridField);
$component = new GridFieldEditableManyManyExtraColumns();
$component->setSaveAutomatically(false);
$fields->dataFieldByName('Billboardy')->getConfig()->addComponent($component, 'GridFieldEditButton');
} else {
$fields->addFieldToTab("Root.Billboardy", new LiteralField("billnote","Billboardy pridáte po prvom uložení"));
}
return $fields;
}
}
Any idea what is wrong? Im using SS 3.0.3.
Best regards
Pali
This seems to be a very useful module, and I don't understand why this hasn't been picked up more.
I was hesitant trying it because it didn't have a composer.json
file, and it actually doesn't work in 3.1. See screenshot.
I'd love to help getting it going, but am having issues wrapping my head around some of the code - maybe we could make this a shared (or sponsored) effort?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.