-
Notifications
You must be signed in to change notification settings - Fork 13
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
Grid Selections Not Being Captured #68
Comments
Thanks for reporting this issue. "Export to CSV" and "Export to Excel" don't take selections into account. The exported data is available in It does work for |
Sure thing. Let me know if/how I can assist. I have a perfect use-case for using this functionality. Cheers. |
@mariobuikhuizen I have a use case too :). I am trying to build a Solara app that renders an ipyaggrid that can crossfilter other Solara components/charts upon rows selection, as shown in this Dash example . But I can't get it to work and I think the issue is due to grid_data_out being one step delayed (async) relative to row selections. I would hate to have to switch to Dash so looking forward to a solution! Cheers |
Can you provide a minimal code example? |
You can use the |
My use case is a bit different. Conceptually, having a grid element like this in a notebook turns the notebook itself into a console which would make managing tables incredibly easy for end users. It also opens the door for some other really cool use cases in a framework I'm building. |
@Lucid-Will , Turns out |
@mariobuikhuizen, apologies if I'm doing something incorrect but I tried the above and unfortunately` having the same issue.
|
For comparison, the below works as expected but doesn't look nearly as awesome as ipyaggrid or have the intended functionality.
|
No worries @Lucid-Will. I've modified your example, this should work: # Sample data
data = {
'ID': [1, 2, 3, 4, 5],
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [24, 30, 35, 22, 29],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix'],
'Subscription': ['Yes', 'No', 'Yes', 'No', 'Yes']
}
# Create DataFrame
pdf_subscription_load = pd.DataFrame(data)
# Preview DataFrame
# display(pdf_subscription_load)
# Set grid options
grid_options = {
'columnDefs': [{'headerName': col, 'field': col, 'checkboxSelection': (col == 'ID'), 'sortable': True, 'filter': True} for col in pdf_subscription_load.columns],
'enableSorting': True,
'enableFilter': True,
'enableColResize': True,
'enableRangeSelection': True,
'rowSelection': 'multiple',
}
# Define grid
grid = Grid(grid_data=pdf_subscription_load,
grid_options=grid_options,
grid_options_multi=[], # Additional grid options for multi-grid setups
columns_fit='size_to_fit',
index=False,
keep_multiindex=False,
compress_data=True,
quick_filter=True, # Enable or disable quick filtering
export_csv=True, # Enable or disable CSV export
export_excel=True, # Enable or disable Excel export
show_toggle_delete=True, # Show or hide delete toggle
show_toggle_edit=True, # Show or hide edit toggle
sync_on_edit=True, # Synchronize edits
sync_grid=True, # Synchronize the grid
paste_from_excel=False, # Allow pasting from Excel
export_mode='buttons', # Set export mode
export_to_df=True, # Export to DataFrame
hide_grid=False, # Hide or show the grid
theme='ag-theme-balham') # Theme
# Assign button
button = widgets.Button(description="Confirm Selection")
def on_rows_selected(change):
selected_rows_df = change["new"].get("rows")
# Check if any rows are selected
if selected_rows_df is None:
print("No rows selected")
else:
# Assuming you have a way to display or use the selected rows DataFrame
print(selected_rows_df) # For demonstration, this will print the DataFrame to the output
# Observe changes in the grid data
grid.observe(on_rows_selected, names=["grid_data_out"])
# Create on_button_click method
def on_button_click(b):
# Use the get_selected_rows method to capture selected rows
grid.get_selected_rows()
# Show grid and button
display(grid)
display(button)
# Bind the callback function to the button
button.on_click(on_button_click) |
@mariobuikhuizen, I really appreciate your support on this! Unfortunately, it appears to be a limitation of the platform I'm trying to run this on (Microsoft Fabric data engineering notebook). I made a few modifications to the update you provided. I'm able to execute the following in VS Code but receive failures when trying to execute in Fabric. I'll keep testing to see if there's a solution and report back. Cheers, and thanks again!
|
One comment about calling |
I've done more testing today and believe that the observer itself isn't functioning as expected in the notebook environment. I also tried in a Synapse Spark notebook. Adding back the print statements for on_row_selection yields no output. Quite a bummer, was a pretty awesome use-case. Cheers again for your help on this. I'll keep an eye on the repo and save my testing for retrying later. Tested code:
Results in Jupyter notebook in Visual Studio Code: Results in Jupyter notebook in Synapse Spark and Fabric notebooks: No print statements upon select: Empty dataframe indicating observer not identifying selections: |
Grid selections aren't being captured by event listener in a Jupyter notebook. I've tried in both Databricks and Microsoft Spark notebooks, neither of which seem to be working.
The grid itself is being populated. I've tested making selections on the grid by row as well as checkbox. I then tested the Export to CSV, Export Rows, Export Columns, and Export Range Data options. Export to CSV creates the CSV export but of the full grid, not the selections. The other export options do not appear to be functioning at all.
I've tried implementing with a button to call grid.get_selected_rows() and capture the selections into a dataframe but the dataframe is empty. I also tried creating a dataframe in a subsequent cell that calls grid.get_selected_rows() as well, also empty dataframe.
I've attached sample notebook code to recreate.
Sample data
Display the DataFrame
Define the grid options with range selection enabled
Create the Grid widget with configured options
Define a button widget
Define an event handler for the button click event
Attach the event handler to the button
Display the Grid widget and the button
The text was updated successfully, but these errors were encountered: