Fix auto export row selection sync by using correct AG Grid event#81
Open
jlancaster7 wants to merge 1 commit intowidgetti:masterfrom
Open
Fix auto export row selection sync by using correct AG Grid event#81jlancaster7 wants to merge 1 commit intowidgetti:masterfrom
jlancaster7 wants to merge 1 commit intowidgetti:masterfrom
Conversation
Change 'rowSelected' to 'selectionChanged' in widget_builder.js. The auto export mode was listening to AG Grid's 'rowSelected' event, which fires per individual row toggle and causes inconsistent selection state during rapid successive updates. The correct event is 'selectionChanged', which fires once after the overall selection state is settled and is the standard event to pair with api.getSelectedRows(). This fixes export_mode='auto' not syncing selected row data from JS to Python via _grid_data_up / grid_data_out. Fixes widgetti#68 Fixes widgetti#76
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
export_mode='auto'is set, clicking a row in the grid should sync the selected row data to Python viagrid_data_outand fireobservecallbacks. Instead,grid_data_outstays empty and no callbacks fire. The grid renders fine and selection highlights visually, but nothing reaches Python.Reported in #68 and #76.
Root Cause
In
js/src/widget_builder.js, the auto export listener for row selection was using AG Grid'srowSelectedevent instead ofselectionChanged:rowSelectedfires once per affected row during a selection change. In single-selection mode, clicking a new row fires it twice (deselect old + select new). The first firing occurs mid-transition whengetSelectedNodes()returns inconsistent state. Both firings callmodel.set('_grid_data_up', ...)in rapid succession, and traitlets silently drops the update because it doesn't detect a meaningful change.selectionChangedfires once after all row selection/deselection is complete. At that point,getSelectedNodes()returns the final, consistent selection state. This is the correct event per AG Grid documentation.Fix
One-line change in
js/src/widget_builder.js:180:Testing
Verified in a Jupyter notebook with the following test cases:
export_mode='auto'+rowSelection: 'single'— clicking a row firesobservecallback ongrid_data_outimmediatelyexport_mode='auto'+rowSelection: 'multiple'— Ctrl+click selects multiple rows, all appear ingrid_data_out['rows']export_mode='auto'+export_to_df=True— selected rows returned as DataFrameexport_mode='auto'+export_to_df=False— selected rows returned as list of dictsexport_mode='buttons'— still works (no regression)get_selected_rows()— still works (no regression)Related Issues
export_mode='auto'selection sync failure reported there.grid.py:241and grouped row handling limitations) that are separate from this fix and remain open.