hyva-themes / magento2-hyva-admin

This module aims to make creating grids and forms in the Magento 2 adminhtml area joyful and fast.
https://hyva-themes.github.io/magento2-hyva-admin/
BSD 3-Clause "New" or "Revised" License
168 stars 39 forks source link

JavaScript Grid Actions #34

Open schmengler opened 3 years ago

schmengler commented 3 years ago

A feature I'd like to see: allow something like "onclick" instead of "url" in grid actions. This allows AJAX requests, popups and other actions that do not require navigating to a new page

Vinai commented 3 years ago

What should the attribute value be... a JavaScript expression, for example a function name? I'm wondering how that could be kept extendable... maybe if it is a JSON object with keys and the values are the callbacks/expressions? E.g.

<action id="example" onclick="{example: openPopup}"/>

In this example, would openPopup be a global function on window? And another question is how could the action rowId value be used in the expression? Maybe with a special $idParam pseudo-variable that get's swapped out with a string_replace?

On the other hand, maybe it's better to keep things simpler and just allow for function names and they are called with the row id param.

Another idea I had was to allow the configuration of events that are dispatched when the trigger happens. Then the subscribers could be anywhere.

<action id="example">
    <event on="onclick"/>
</action>

This would trigger an event with the name hyva_grid_[grid-name]_example_onclick. I like this approach because it makes it easy to extend and pass multiple arguments.

schmengler commented 3 years ago

That's a good thing to discuss openly, I don't have a strong opinion on how it should work.

~But the event suggestion sounds elegant to me and matches the Hyvä spirit. How would you add arguments though?~ Nevermind, I'm looking at #35 now :)