How to handle click events #249
Replies: 5 comments 3 replies
-
I'm glad you are enjoying your time with trame. So when you want to pass arguments to an event you can do it as follow with vuetify.Template(slot ="item.actions", slot_props ="{ item }"):
vuetify.VIcon(small=True, children=["mdi-pencil"], click =(handle_click, "['edit', item]"))
vuetify.VIcon(small=True, children=["mdi-delete"], click =(handle_click, "['delete', item]")) So the basic gist is |
Beta Was this translation helpful? Give feedback.
-
BTW, you should set your icons as follow vuetify.VIcon("mdi-pencil", small=True, click=(handle_click, "['edit', item]")) The first arg is the element child. |
Beta Was this translation helpful? Give feedback.
-
I’m on my phone so I can’t provide the full code but the {item} should come
from your parent slot like you had it in your code.
Although looking at it, I think you have a some syntax issue.
To debug you should print the “layout.html” and compare it with the vuetify
example.
Also look at the course reference slides. They may help you.
Good luck
…On Thu, Apr 27, 2023 at 02:25 janegliese ***@***.***> wrote:
Thanks! So I modified the code like below, but getting the error:
JS Error => ReferenceError: item is not defined
def handle_click(action, item):
print("Action:", action)
print("Item:", item)
with SinglePageWithDrawerLayout(server) as layout:
with layout.content:
with vuetify.VDataTable(**table) as data_table:
with vuetify.Template(slot ="item.actions", slot_props ="{ item }"):
vuetify.VIcon("mdi-pencil", small=True, click=(handle_click, "['edit', item]"))
vuetify.VIcon("mdi-delete", small=True, click=(handle_click, "['delete', item]"))
—
Reply to this email directly, view it on GitHub
<#249 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACH45WUZYS2CWW2JOBVFLLXDINNNANCNFSM6AAAAAAXNAUMNE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the pointers! I've been at it for a while but still at a loss. From the referenced example:
As i understand the syntax (referencing this #241) I've tried a few different ways to define the tempate to try and understand and match the html from the example.
Setting it as vuetify.Template (v_slot_item = { item }) will make the items accessible but obviously wont put them in the actions column in the VDataTable.
|
Beta Was this translation helpful? Give feedback.
-
Until you get the exact matching string, it won’t work. If you want you can
write it as a string by doing a call like table.add_child(“……”)
…On Fri, Apr 28, 2023 at 12:38 janegliese ***@***.***> wrote:
Thanks for the pointers! I've been at it for a while but still at a loss.
Obviously there is a difference between the expected output from the
example and the printed layout.
Below is the expected output from the referenced example as well as two
printed html layouts.
From the referenced example:
<template v-slot:item.actions="{ item }">
<v-icon
small
class="mr-2"
@click="editItem(item)"
>
mdi-pencil
</v-icon>
<v-icon
small
@click="deleteItem(item)"
>
mdi-delete
</v-icon>
</template>
As i understand the syntax (referencing this #241
<#241>)
v-slot:item_actions = " { item } " should be written as
v_slot_item_actions = "{ item }"I dont get it to work to work though with
no html output for the template when printing it.
I've tried a few different ways to define the tempate to try and
understand and match the html from the example.
E.g. defining it with:
with vuetify.Template(slot="item.actions", slot_props = { item }): will
place the item.actions correctly, however the item wont be made accesible.
(setting v_slot instead of slot results in a 405 error).
Printed layout for with vuetify.Template (slot = "item.actions",
slot_props = { item } ):
`<template slot="item.actions">
<v-icon small @click="trigger('trigger__1', ['edit', item])">
mdi-pencil
</v-icon>
<v-icon small @click="trigger('trigger__1', ['delete', item])">
mdi-delete
</v-icon>
</template>
Setting it as vuetify.Template (v_slot_item = { item }) will make the
items accessible but obviously wont put them in the actions column in the
VDataTable.
Printed layout for `vuetify.Template (v_slot_item = { item }):
`<template v-slot:item="{ item }">
<v-icon small @click="trigger('trigger__1', ['edit', item])">
mdi-pencil
</v-icon>
<v-icon small @click="trigger('trigger__1', ['delete', item])">
mdi-delete
</v-icon>
</template>
—
Reply to this email directly, view it on GitHub
<#249 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACH45VH7NVYEJQBNVRW3MTXDOM2DANCNFSM6AAAAAAXNAUMNE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi! First of all, thanks for this amazing library, been having lots of fun rebuilding some old streamlit apps with it!
So what I am trying to do is recreate this example:
https://v2.vuetifyjs.com/en/components/data-tables/#crud-actions
I believe I've managed with the layout, but I'm having issues handling the click events.
Currently the returned kwargs is an empty dictionary.
Here's the part of the code that i believe is the most relevant to the issue:
And below is the full runnable code:
Beta Was this translation helpful? Give feedback.
All reactions