ipyvuetify icon indicating copy to clipboard operation
ipyvuetify copied to clipboard

Passing data via v_slots

Open fekete42 opened this issue 4 years ago • 3 comments

Hi,

I'd like to ask if the following feature is available in ipyvuetify. What I want to achieve is to use the v_slots mechanism to pass data between widgets. The following is a simple example.

Let's assume we have a data table and we want to use buttons in one of the columns. With the ipyvuetify template widget this is achievable like this:

import ipyvuetify as v
import traitlets

data = {'headers': [{'text': 'A', 'value': 'A'},
                    {'text': 'B', 'value': 'B'},],
        'items': [{'A': '10', 'B': 'a'},
                  {'A': '20', 'B': 'b'},
                  {'A': '30', 'B': 'c'},]}

class CustomDataTable(v.VuetifyTemplate):
    headers = traitlets.List([]).tag(sync=True, allow_null=True)
    items = traitlets.List([]).tag(sync=True, allow_null=True)
    template = traitlets.Unicode('''
        <template>
            <v-data-table
                :headers="headers"
                :items="items"
            >
            <template v-slot:item.A="btn">
              <v-btn color="primary">
              {{ btn.value }}
            </v-btn>
            </template>
            </v-data-table>
        </template>
        ''').tag(sync=True)

CustomDataTable(headers=data['headers'], 
                items=data['items'])

The output looks like this, the items in column A are displayed as buttons: image

I'd like to replicate the same by using the existing DataTable and Btn widgets. Composing widgets in python would be much more flexible. Unfortunately, I was unable to figure it out how I could pass variables, in this case {{ btn.value }}, through v_slots.

v.DataTable(headers=data['headers'], 
            items=data['items'], 
            v_slots=[{'name': 'item.A', 
                    'variable': 'btn', 
                    'children': [v.Btn(color='primary', children=['{{ btn.value }}'])]}])

image

As the image shows, the buttons are included in the table, but the labels on the buttons are not displayed properly.

Is it possible to obtain the same output as what I obtained with the template widget above?

fekete42 avatar Mar 11 '21 15:03 fekete42

The {{ ... }} syntax only works in the Vue template. In ipyvuetify we only support the passing of events in v-slots, so tooltips and menus are supported. Ipyvuetify can not support evaluating/executing javascript inside v-slots, so the template is the only option to support this.

mariobuikhuizen avatar Mar 16 '21 10:03 mariobuikhuizen

Would it be possible to use a template in v-slots and establish a link of javascript variables via the python API or it's also a dead-end idea?

fekete42 avatar Mar 29 '21 09:03 fekete42

items=[{ 'id': 1, 'name': 'Applications :', 'value':3, 'children': [ { 'id': 2, 'name': 'Calendar','value':55 },

], }]

v_slots=[{ 'name': 'prepend', 'variable': 'item',
'children': v.Btn(color='primary', children=['{{ item.value }}'])]}] treeview = rv.Treeview( items=items. v_slots=v_slots )

same as upper ,I need to show Button with item value how to do this?

wjcroom avatar Apr 03 '24 01:04 wjcroom