-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding oncellclicked event using ipyaggrid #21
Comments
I don't know the answer to this specific question, did you check out the https://github.com/widgetti/ipyaggrid/tree/master/docs/notebooks directory. Maybe that helps you in the right direction |
You can add an even by adding a callback for
|
Thanks @vthemelis |
I don't think that this is something that is possible to do right-off-the-box in ipyaggrid. You would probably need some sort of IPC framework for this. Maybe this: https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Low%20Level.html#comms ? |
Here's a workaround using ipyvue: import ipyaggrid as ipg
import pandas as pd
import ipyvue
import traitlets
class MyEvents(ipyvue.VueTemplate):
@traitlets.default("template")
def _template(self):
return """
<script>
module.exports = {
created() {
window.myNamespace = {
passEvent: (params) => {
this.my_message(params)
},
}
}
}
</script>
"""
def vue_my_message(self, data):
print("data: ", data)
display(MyEvents())
# Create a sample dataframe
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Charlie'],
'age': [25, 30, 35],
'salary': [50000, 60000, 70000]
})
# Define the Ag-Grid column definitions
column_defs = [
{'headerName': 'Name', 'field': 'name'},
{'headerName': 'Age', 'field': 'age'},
{'headerName': 'Salary', 'field': 'salary'},
]
# Define the Ag-Grid options
options = {
'column_defs': column_defs,
'enableSorting': True,
'enableFilter': True,
'enableColResize': True,
'onCellClicked': '''function(params) {
console.log("params: ", params);
const { rowIndex, type, data } = params;
myNamespace.passEvent({ rowIndex, type, data });
}'''
}
# Create the Ag-Grid widget
grid_widget = ipg.Grid(
grid_data=df,
grid_options=options
)
# grid_widget.on_msg(lambda *args: print("onmsg", args))
# Display the widget
grid_widget |
Hi,
I'm trying to add an oncellclicked event to my table where the cell value is returned when user click the cell, I know this is possible using AG grid, just wondering is there a way to add this event using Python. Thanks!
The text was updated successfully, but these errors were encountered: