Trying to use the Grid field in my addon settings page: https://docs.expressionengine.com/latest/development/services/table.html
However, using this code in my template to render the grid html doesn’t work:
<?php $this->view('_shared/table', $grid); ?>
It outputs a PHP error:
Fatal error: Call to undefined method EllisLab\ExpressionEngine\Service\View\View::view() in views/filename.php
I see the native addons use $this->embed(‘_shared/table’, $table); instead of $this->view() but if I try that I’ll just get “View file not found”.
You should be using $this->embed()
, sorry, I’ll update the docs for that. Since you’re using it in an add-on, you have to specify the namespace. Try this:
$this->embed('ee:_shared/table', $table);
I’ll update the docs for that, too.
As for the add_new_row, try loading the content_lang file, or specify a lang key of “add_new_row” yourself and make it anything you want.
As for the JS seemingly not working, did you call loadAssets()
on the Grid object?
As for the JS seemingly not working, did you call loadAssets() on the Grid object?
I’ve called loadAssets(). I think the JS is working fine, as the remove row option works (although it doesn’t do anything else than remove the row visually).
”+” does nothing though.
How to I hook onto the “+” and “remove row” to make sure it does what I want them to do?
Also, it just occurred to me that it might be better to use Table if Grid handles the storing of data. Does it? I’m already storing the data in my own table (converting an existing addon).
Thanks!
”+” does nothing though.
Hard to say. Are you using the shared form view to make this? If so, do you have the grid
setting set on your fieldset definition? If not, have you followed the style guide in implementing Grid? It needs to live in a fieldset with a class of grid-publish
.
How to I hook onto the “+” and “remove row” to make sure it does what I want them to do?
You can write your own click handlers for them if you want via jQuery.
Also, it just occurred to me that it might be better to use Table if Grid handles the storing of data. Does it? I’m already storing the data in my own table (converting an existing addon).
No, storing and populating the data is up to you, GridInput just provides the UI.
Hard to say. Are you using the shared form view to make this? If so, do you have the grid setting set on your fieldset definition?
Fieldset definition? This is just used in the control panel file (mcp) of my addon.
You can write your own click handlers for them if you want via jQuery.
Yeah, is that the correct way of doing it? I’m confused as the docs have a section for using Grid in the CP file but no further info on how to hook onto the “Delete row” / Add new row functionality.
Fieldset definition? This is just used in the control panel file (mcp) of my addon.
I’m not sure what you’re trying to say. How are you generating the markup that surrounds your Grid input?
Yeah, is that the correct way of doing it? I’m confused as the docs have a section for using Grid in the CP file but no further info on how to hook onto the “Delete row” / Add new row functionality.
We wouldn’t document it because it should be unnecessary to do. If you get the Grid JS working as it should, then these buttons work as intended. I was answering the question from the point of view of if you’re not happy with what those buttons do, then you can create your own click handler, but we wouldn’t want to encourage that because it may introduce inconsistency in the UI.
Ok, so wrapping it in the code from the styleguide makes the “+” actually do something, which is good, but I get a JS error: http://i.imgur.com/OcB9cJw.jpg
The docs could use a complete example for this .. right now the Grid section under the CP/Table service makes no mention of the required code around it.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.