Skip to content

Commit 4b26db9

Browse files
Copilotdsmmcken
andcommitted
Reorganize Events section: move always_fetch_columns to end, add links, rename to Selection Events
Co-authored-by: dsmmcken <1576283+dsmmcken@users.noreply.github.com>
1 parent 6426411 commit 4b26db9

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

plugins/ui/docs/components/table.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ t_top = ui.table(
404404

405405
### Press Events
406406

407-
You can listen for different user press events on a `ui.table`. There is both a `press` and `double_press` event for `row`, `cell`, and `column`. These events typically correspond to a click or double click on the table. The event payloads include table data related to the event. For `row` and `column` events, the corresponding data within the viewport will be sent to the event handler. The viewport is typically the visible area &plusmn; a window equal to the visible area (e.g., if rows 5-10 are visible, rows 0-15 will be in the viewport).
407+
You can listen for different user press events on a `ui.table`. There is both a `press` and `double_press` event for `row`, `cell`, and `column`. These events typically correspond to a click or double click on the table. The event payloads include table data related to the event. For `row` and `column` events, the corresponding data within the viewport will be sent to the event handler. The viewport is typically the visible area &plusmn; a window equal to the visible area (e.g., if rows 5-10 are visible, rows 0-15 will be in the viewport). Data specified via [`always_fetch_columns`](#always-fetching-some-columns) is also included.
408408

409409
Note that there is no row index in event data because the row index is not a safe way to reference a row between the client and server since the user could have manipulated the table, resulting in a different client order.
410410

@@ -427,49 +427,49 @@ t = ui.table(
427427
)
428428
```
429429

430-
### Always fetching some columns
431-
432-
Deephaven only fetches data for visible rows and columns within a window around the viewport (typically the viewport plus 1 page in all directions). This reduces the amount of data transferred between the server and client and allows tables with billions of rows to be displayed. Sometimes you may need to always fetch columns, such as a key column for a row press event. You can use the `always_fetch_columns` prop to specify columns that should always be fetched regardless of their visibility.
433-
434-
The `always_fetch_columns` prop takes a single column name, a list of column names, or a boolean to always fetch all columns. The data for these columns is included in row event data (e.g., `on_row_press`) and context menu callbacks.
430+
### Selection Events
435431

436-
When using event callbacks, include any columns referenced in the callback in `always_fetch_columns` to prevent undefined columns when users hide columns or scroll beyond the viewport.
432+
The `on_selection_change` event is triggered when the user selects or deselects a row. The event data will contain all selected rows within the viewport as a list of dictionaries keyed by column name. There are a few caveats to the selection event.
437433

438-
> [!WARNING]
439-
> Setting `always_fetch_columns` to `True` will fetch all columns and can be slow for tables with many columns.
434+
1. The event will **only** send data from columns in the [`always_fetch_columns`](#always-fetching-some-columns) prop.
435+
2. The event will **only** send data from rows that are visible in the viewport.
436+
3. The event will **not** be triggered if a ticking table row is replaced or shifted. This may cause what the user sees after row shifts to differ from the selection event data.
440437

441-
This example shows how to use `always_fetch_columns` to always fetch the `Sym` column for a row press event. Without the `always_fetch_columns` prop, the press callback will fail because the `Sym` column is not fetched when hidden.
438+
With these caveats in mind, it is highly recommended that the `on_selection_change` event be used only with static tables. It is also recommended to only use this event for relatively small actions where you can see all selected rows at once.
442439

443440
```python
444441
from deephaven import ui
445442
import deephaven.plot.express as dx
446443

447444
t = ui.table(
448445
dx.data.stocks(),
449-
hidden_columns=["Sym"],
450-
on_row_press=lambda d: print(d["Sym"]),
451-
always_fetch_columns="Sym",
446+
on_selection_change=lambda data: print(f"Selection: {data}"),
447+
always_fetch_columns=["Sym", "Exchange"],
452448
)
453449
```
454450

455-
### Selection Event
451+
### Always fetching some columns
456452

457-
The `on_selection_change` event is triggered when the user selects or deselects a row. The event data will contain all selected rows within the viewport as a list of dictionaries keyed by column name. There are a few caveats to the selection event.
453+
Deephaven only fetches data for visible rows and columns within a window around the viewport (typically the viewport plus 1 page in all directions). This reduces the amount of data transferred between the server and client and allows tables with billions of rows to be displayed. Sometimes you may need to always fetch columns, such as a key column for a row press event. You can use the `always_fetch_columns` prop to specify columns that should always be fetched regardless of their visibility.
458454

459-
1. The event will **only** send data from columns in the `always_fetch_columns` prop.
460-
2. The event will **only** send data from rows that are visible in the viewport.
461-
3. The event will **not** be triggered if a ticking table row is replaced or shifted. This may cause what the user sees after row shifts to differ from the selection event data.
455+
The `always_fetch_columns` prop takes a single column name, a list of column names, or a boolean to always fetch all columns. The data for these columns is included in row event data (e.g., `on_row_press`) and context menu callbacks.
462456

463-
With these caveats in mind, it is highly recommended that the `on_selection_change` event be used only with static tables. It is also recommended to only use this event for relatively small actions where you can see all selected rows at once.
457+
When using event callbacks, include any columns referenced in the callback in `always_fetch_columns` to prevent undefined columns when users hide columns or scroll beyond the viewport.
458+
459+
> [!WARNING]
460+
> Setting `always_fetch_columns` to `True` will fetch all columns and can be slow for tables with many columns.
461+
462+
This example shows how to use `always_fetch_columns` to always fetch the `Sym` column for a row press event. Without the `always_fetch_columns` prop, the press callback will fail because the `Sym` column is not fetched when hidden.
464463

465464
```python
466465
from deephaven import ui
467466
import deephaven.plot.express as dx
468467

469468
t = ui.table(
470469
dx.data.stocks(),
471-
on_selection_change=lambda data: print(f"Selection: {data}"),
472-
always_fetch_columns=["Sym", "Exchange"],
470+
hidden_columns=["Sym"],
471+
on_row_press=lambda d: print(d["Sym"]),
472+
always_fetch_columns="Sym",
473473
)
474474
```
475475

0 commit comments

Comments
 (0)