magento2-hyva-admin
magento2-hyva-admin copied to clipboard
Insert Grid into Forms
Hi Vinai,
More of a question than an issue.
Is there currently any documentation surrounding inserting a grid into a form? I can add the grid into the form ui component using <htmlContent>
<htmlContent name="my_hyva_grid">
<settings>
<additionalClasses>
<class name="admin__field">true</class>
</additionalClasses>
<dataScope>my_hyva_grid</dataScope>
</settings>
<block class="Hyva\Admin\Block\Adminhtml\HyvaGrid" name="my-hyva-grid"/>
</htmlContent>
However when it comes to replicating the default Magento functionality of exports
, imports
, links
and listens
to be able to filter the inserted grid and add an insetForm for example I'm unsure if you have a way around this or not?
Thanks!
Looks like I may have found an answer to the above here in the docs
Is there are way to trigger the grid to refresh in an external javascript component after say adding a new entity within an InsetForm?
Thanks.
This feels rather hacky and maybe not the right way however one way to achieve this would be something along the lines of:
- Pass an argument to the Hyva Grid Block to identify the grid or maybe even use the $block->getUiId()?
- Pass that same identifier to a custom Javascript component, extending say the form.js
- Trigger a grid update on form save action along the same lines as the ajax update when the current pagination filter is used
Aware this may all change when the "Forms" feature is released if it supports inset Hyva Grids?
You could trigger an update of the grid using ajaxGridUpdate
on the Alpine view model.
Currently the method is not exposed to global scope, but maybe you could work around this by using something like
function updateGrid() {
const grid = document.querySelector('.hyva-admin-grid'); // assuming there is only one grid on the page
const viewModel = grid.__x.$data;
viewModel.ajaxGridUpdate(viewModel.filterUri);
}
Then call doUpdate()
whenever you want to reload the grid...
It for sure is hacky as heck :)
Thanks Vinai, love the idea just not comfortable with the implementation! I think I may hold of on this and revert back to the default insetListing and insetForm for now.
Is this something that will be available with the Forms work you are doing being able to inline Hyva Grids, or should it be a separate feature request for people to collab on?
Currently I'm focused on bugfixes for the grid and on finally getting the first version of forms support out the door. If you feel like it, I would appreciate a PR very much!