magento2-hyva-admin
magento2-hyva-admin copied to clipboard
JavaScript Grid Actions
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
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.
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 :)