Skip to content

Commit a951480

Browse files
Copilotdsmmcken
andcommitted
Move always fetch columns section to events section and add best practices
Co-authored-by: dsmmcken <1576283+dsmmcken@users.noreply.github.com>
1 parent 5761a7e commit a951480

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

plugins/ui/docs/components/table.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,32 @@ 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 displaying tables with billions of rows. 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.
435+
436+
> [!TIP]
437+
> **Best Practice for Event Callbacks**: When using event callbacks (such as `on_row_press`, `on_cell_press`, or `on_selection_change`), it's recommended to include any column you will be using in the callback in `always_fetch_columns`. This prevents potentially undefined columns if users hide those columns or scroll far right where the original columns are no longer in the viewport.
438+
439+
> [!WARNING]
440+
> Setting `always_fetch_columns` to `True` will fetch all columns and can be slow for tables with many columns.
441+
442+
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.
443+
444+
```python
445+
from deephaven import ui
446+
import deephaven.plot.express as dx
447+
448+
t = ui.table(
449+
dx.data.stocks(),
450+
hidden_columns=["Sym"],
451+
on_row_press=lambda d: print(d["Sym"]),
452+
always_fetch_columns="Sym",
453+
)
454+
```
455+
430456
### Selection Event
431457

432458
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.
@@ -610,29 +636,6 @@ t = ui.table(
610636

611637
![Example of column groups](../_assets/table_column_groups.png)
612638

613-
## Always fetching some columns
614-
615-
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 displaying tables with billions of rows. 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.
616-
617-
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.
618-
619-
> [!WARNING]
620-
> Setting `always_fetch_columns` to `True` will fetch all columns and can be slow for tables with many columns.
621-
622-
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.
623-
624-
```python
625-
from deephaven import ui
626-
import deephaven.plot.express as dx
627-
628-
t = ui.table(
629-
dx.data.stocks(),
630-
hidden_columns=["Sym"],
631-
on_row_press=lambda d: print(d["Sym"]),
632-
always_fetch_columns="Sym",
633-
)
634-
```
635-
636639
## Quick filters
637640

638641
Quick filters are an easy way to filter the table while also showing the user what filters are currently applied. These filters are applied on the server via request from the client, so users may change the filters without affecting other users. Unlike a `where` statement to filter a table on the server, quick filters can be easily changed by the user.

0 commit comments

Comments
 (0)