From 740110f87f6a44a980746255478978007bd997df Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 14 Jan 2025 18:15:22 -0600 Subject: [PATCH] fix: add `click_handler` attr for GridAction sometimes caller just needs to do something unique, so let them --- src/wuttaweb/grids/base.py | 12 ++++++++++++ src/wuttaweb/templates/grids/vue_template.mako | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/wuttaweb/grids/base.py b/src/wuttaweb/grids/base.py index e65a22e..33269f2 100644 --- a/src/wuttaweb/grids/base.py +++ b/src/wuttaweb/grids/base.py @@ -2284,6 +2284,16 @@ class GridAction: Optional ``target`` attribute for the ```` tag. + .. attribute:: click_handler + + Optional JS click handler for the action. This value will be + rendered as-is within the final grid template, hence the JS + string must be callable code. Note that ``props.row`` will be + available in the calling context, so a couple of examples: + + * ``deleteThisThing(props.row)`` + * ``$emit('do-something', props.row)`` + .. attribute:: icon Name of icon to be shown for the action link. @@ -2302,6 +2312,7 @@ class GridAction: label=None, url=None, target=None, + click_handler=None, icon=None, link_class=None, ): @@ -2311,6 +2322,7 @@ class GridAction: self.key = key self.url = url self.target = target + self.click_handler = click_handler self.label = label or self.app.make_title(key) self.icon = icon or key self.link_class = link_class or '' diff --git a/src/wuttaweb/templates/grids/vue_template.mako b/src/wuttaweb/templates/grids/vue_template.mako index ac0a2a9..ba548cb 100644 --- a/src/wuttaweb/templates/grids/vue_template.mako +++ b/src/wuttaweb/templates/grids/vue_template.mako @@ -183,6 +183,9 @@ % if action.target: target="${action.target}" % endif + % if action.click_handler: + @click.prevent="${action.click_handler}" + % endif class="${action.link_class}"> ${action.render_icon_and_label()}