Skip to content
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

Support for Selecting rows? #250

Closed
jnaylor92 opened this issue Mar 27, 2024 · 10 comments · Fixed by #319
Closed

Support for Selecting rows? #250

jnaylor92 opened this issue Mar 27, 2024 · 10 comments · Fixed by #319

Comments

@jnaylor92
Copy link

I see that DataTables supports row select: https://datatables.net/examples/api/select_row.html

Is there any plan to include this in itables?

@mwouts
Copy link
Owner

mwouts commented Mar 27, 2024

Hi @jnaylor92 , well actually the selection extension is included in ITables! It's a requirement for the SearchPanes and SearchBuilder extensions.

I did not add an example for that extension since I was not sure how to use that information back in Python - do you have a plan for that?

See also #208 for an example on how to retrieve the selected row in the context of a Shiny app (with an older version of ITables).

@jnaylor92
Copy link
Author

A very simple example would be something like:

from itables.sample_dfs import get_countries
from itables import init_notebook_mode, show

init_notebook_mode(connected=False)
countries_table = show(get_countries(), connected=False)

selected_countries - countries_table.get_selected()

I really like ITables for what it gives and the way it looks in comparison to something like qgridnext which gives selection but not whole table search and pagination.

I am trying to build up an interactive form that includes displaying a table of data for the user to select samples to then do something further with. Using the above example it might be to plot the selected countries on a map using the lat / long

@mwouts
Copy link
Owner

mwouts commented Mar 28, 2024

I see. Well at the moment there is no direct way to retrieve the selected rows in ITables. That might come at a later stage when we improve the support for "apps" (i.e. Dash, Shiny, or Python widgets), but there is no ETA for that at the moment, for now ITables is "display only". Please leave the issue open though, so that I can give an update when the situation changes.

@jnaylor92
Copy link
Author

That all makes sense and it is good to hear there is a plan to head in that direction in the future. Appreciate the quick responses

@ronnystandtke
Copy link

This feature would be awesome!
I use itables in a simple JupyterLite notebook to complement a map of bridges:
https://ronnystandtke.github.io/KUBA/lab?path=KUBA.ipynb
I would absolutely love to be able to select an entry in the table and jump to the bridge in the map. Any way to detect the selection in the table would be very helpful.

@mwouts
Copy link
Owner

mwouts commented Jun 20, 2024

Sure! That will come at some point.

Already we have made progress with the apps - now we do have a streamlit component. I think I'd like to get at least a second "app" component, ideally a jupyter widget (#267), before I expose the selected cells (without the widget I'm not sure how you'd get a callback on selection changes).

NB:

  1. If you're at ease with JavaScript you might also try to port this example that worked with an earlier version of ITables in the context of a Shiny app: Row selection? #208 (comment)
  2. The DataTable css seems to be missing from your app (the buttons have a odd look), I'm not sure what can cause this?

@ronnystandtke
Copy link

2. The DataTable css seems to be missing from your app (the buttons have a odd look), I'm not sure what can cause this?

I was also wondering about this. I use a plain simple JupyterLite notebook with a basic requirements list:
https://github.com/ronnystandtke/KUBA/blob/main/requirements.txt
In the notebook itself I install itables via the built-in magic command %pip:
%pip install -q itables
Am I missing something?

@mwouts
Copy link
Owner

mwouts commented Sep 12, 2024

Hi @AllanJard, now that I have a streamlit component and almost a Jupyter Widget (#267), I would like to give access to the selected rows.

The problem is that I am not sure how to convert table.rows('.selected') to an array of numbers (the selected row indices). Would you have an example around? Thanks!

@AllanJard
Copy link

You want the rows().indexes() chained method most likely. That will give you the "data index" (i.e. the order in which it was loaded into DataTables. You might be interested in the rows().ids() method to get row ids if they are defined. They are often more useful externally.

Finally, use .rows({selected: true}) to get selected rows rather than the .selected class selector. The reason for that is that the class selector will only work with rows which have already been rendered. That might not be the case if Ajax / JS loaded data is used and the user does an action (e.g. "Select all") that selects rows which have not yet been made visible.

@mwouts
Copy link
Owner

mwouts commented Sep 16, 2024

The new ITable widget in ITables v2.2 has a selected_rows trait, see the documentation

mwouts added a commit that referenced this issue Sep 22, 2024
Selected rows in the widget, in Streamlit and in Shiny (#250)
Version 2.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants