-
Notifications
You must be signed in to change notification settings - Fork 51
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
methods for robustly retrieving key
of selected_cells
#340
Comments
I noted this as a "feature-request" but i think that the following linked behaviour could be considered a bug... here:
|
digging a bit deeper - it appears that selections and transforms and mutually exclusive... |
for my immediate requirement I did something akin to: class GridWrapper(DataGrid):
def __init__(df, **kwargs):
super().__init__(df, **kwargs)
@property
def selected_rows_data(self):
"""Get the data selected in the table which is returned as a dataframe."""
s = self.selected_visible_cell_iterator
rows = set([l["r"] for l in s])
return [s._data["data"][r] for r in rows]
@property
def selected_keys(self):
"""Return the keys of the selected rows."""
s = self.selected_visible_cell_iterator
index = self.get_dataframe_index(self.data)
rows = set([l["r"] for l in s])
return [s._data["data"][r][index] for r in rows]
@property
def selected_visible_cell_iterator(self):
"""
An iterator to traverse selected cells one by one.
Identical to the `selected_cell_iterator` property but the SelectionHelper
is initiated from the visible data only.
"""
# Copy of the front-end data model
view_data = self.get_visible_data()
# Get primary key from dataframe
index_key = self.get_dataframe_index(view_data)
# Serielize to JSON table schema
view_data_object = self.generate_data_object(view_data, "ipydguuid", index_key)
return SelectionHelper(view_data_object, self.selections, self.selection_mode) this way accessing the I'll leave this open as it took me a while (and some digging in the source code) to understand that was what I needed to do. If you think that these methods (or similar) would be a useful addition to the source code I'll happily make a PR, or if I've missed something about how to achieve the desired outcome another way I'm keen to understand it. many thanks |
@jgunstone Thank you so much for taking the time to compose and post your findings 🙏. I will be pushing bug fixes and some enhancements in the next couple of weeks, so will definitely get back to you. |
you're most welcome and I'm looking forward to the updates! many thanks |
Is your feature request related to a problem? Please describe.
I have a workflow where users select an ipydatagrid row, press a button to edit the row data (using ipywidgets), and then save the edit back to the grid. Users continually use the column filters to navigate to appropriate rows, and ideally the workflow can work independently of where a filter is applied.
the process i'd like to follow is:
the problem I'm having is with retrieving the row index for a selected row.
the
grid.selected_cells
method returns the cells, but the row indexes match up with filtered table rather than the un-filtered tableunfiltered:
filtered:
so
grid.selected_cells
returns rows == 0 and 1 whereas the keys to look up the data fromgrid.data
orgrid._data['data']
is actually 0 and 4Describe the solution you'd like
it would be great if the the
grid.selected_cells
method returned the row numbers for the base data rather than the filtered grid (or if there was an additional method for this).Describe alternatives you've considered
I did have a method where I:
grid.selected_cells
grid.get_visible_data()
this was a bit hacky, but appeared to work. but then it fell down if sorting was applied...
many thanks!
The text was updated successfully, but these errors were encountered: