Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert Grid into Forms #59

Open
mattgrul opened this issue Jul 6, 2021 · 5 comments
Open

Insert Grid into Forms #59

mattgrul opened this issue Jul 6, 2021 · 5 comments

Comments

@mattgrul
Copy link
Contributor

mattgrul commented Jul 6, 2021

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 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!

@mattgrul
Copy link
Contributor Author

mattgrul commented Jul 6, 2021

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.

@mattgrul
Copy link
Contributor Author

mattgrul commented Jul 7, 2021

This feels rather hacky and maybe not the right way however one way to achieve this would be something along the lines of:

  1. Pass an argument to the Hyva Grid Block to identify the grid or maybe even use the $block->getUiId()?
  2. Pass that same identifier to a custom Javascript component, extending say the form.js
  3. 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?

@Vinai
Copy link
Collaborator

Vinai commented Jul 7, 2021

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 :)

@mattgrul
Copy link
Contributor Author

mattgrul commented Jul 7, 2021

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?

@Vinai
Copy link
Collaborator

Vinai commented Jul 7, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants