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.

We've moved the forum!

Please use 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.

Data Model Questions /

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

Gridfield not populate with ArrayList when not in public function getCMSFields

Go to End

2 Posts   1822 Views


Community Member, 7 Posts

6 July 2016 at 1:21am

Edited: 06/07/2016 5:59pm

When I create GridField within admin console - everything is ok - I cam populate gridfield via classic method (ex. Member::get() - - or via ArrayList -

 $al1 = new ArrayList();
$records = DB::query("SELECT * from Member where id<10");
while($rec = $records->next()) {
$al1->push(new ArrayData($rec));
$grid = new GridField('Pages', 'All pages', $al1) 

Both methods are working ok. However, If I try to create GridField on user page - - presented in a form - - somehow the second method (where GridField should be populated by ArrayList - is not working).

$gridField = new GridField('pages1', 'All pages1', Member::get(), $config); 

- woks ok, but the method where I create ArrayList oldfashioned way:

$al = new ArrayList();
$records = DB::query("SELECT * from Member where id<10");
while($rec = $records->next()) {
$al->push(new ArrayData($rec));

i get an error when I tr to render gridfield throug:

return new Form($this, "AllSubmissions", new FieldList($gridField), new FieldList());

Since I need data from external database to populate gridfield on non admin pages, I am desperate to get the solution for this. If someone can provide me alternative method to show/edit tabular data in Silverstripe - -would appreciate very much. Best regards, Grega


Community Member, 791 Posts

18 July 2016 at 8:26pm

Edited: 18/07/2016 9:48pm

I bumped into the same problem. The error message is a bit obscure, but I solved it by explicitly defining the displayfields for the gridfield.


// GridField configuration
		$config = $gridField->getConfig();
		$dataColumns = $config->getComponentByType('GridFieldDataColumns');

			'Name' => 'Title',

ps (Thanks to Simon Erkelens for pointing me in the right direction !)