Setting up Tabulator columnCellContextMenu - Part 2

I’m following up on my initial post regarding a solution to creating a Tabulator cell context menu, which I still have not had any success solving: Setting up Tabulator columnCellContextMenu

Tabulator docs show that cell context menu needs to be defined at column level but I don’t believe Python support that:

columns:[
        {title:"Name", field:"name", width:200, contextMenu:cellContextMenu}, //add a context menu to the cells in this column
    ]

I do have a simple example with the global row context working:
https://anvil.works/build#clone:4DXIQU2SB5IA6JUL=5AZVC3CIOJOJP737O6AIC32H

Any suggestions for how that cell context menu might be implemented?

Thanks!

since the cellContextMenu requires a javascript function for action there’s no easy way to do this with the tools available…

You currently have in javascript:

    var cellContextMenu = [
        {
            label:"Cell Context Menu Item",
            action:function(e, cell){
                alert("cell context item clicked!");
            }
        }
    ];

Things like dictionaries, lists, strings, ints, floats are easily converted between python and javascript via the call_js method. But functions… not so much

javascript function --> python is possible
python function --> javascript not possible 

So this is the sticking point. If you want an action that is a python function you can’t just do:

contextMenu =[
        {
            'label':"Cell Context Menu Item",
            'action' : lambda(e, cell): alert('cell context clicked')
            }
    ]

because there’s no easy transform between a python function to a javascript function…

Thanks for your response.
I came to the same conclusion about python->js conversion.

What I need is not so much a python function in the context menu, but a way to add the “contextMenu:cellContextMenu” into the column list of dicts; but still the same issue.

Thanks.

1 Like