Skip to contents

Updates the selection state of a DataTable (DT) component when a shared ID is selected or deselected from another linked component. This function handles both custom click handlers and default selection behavior.

Usage

update_dt_selection(component_id, selected_id, session, components)

Arguments

component_id

Character string. The ID of the DT component to update.

selected_id

The shared ID value to select. If NULL, deselects all rows.

session

Shiny session object for the current user session.

components

List containing component configuration information, including data reactives, shared ID columns, and optional custom click handlers.

Value

NULL (invisible). Function is called for side effects only.

Details

The function performs the following steps:

  • Validates that the DT package is available

  • Retrieves current data from the component's reactive data source

  • Validates that the shared ID column exists in the data

  • Creates a DT proxy for programmatic table manipulation

  • Finds the matching row based on the shared ID

  • Executes either custom click handler or default selection behavior

Custom Click Handlers

If a custom click handler is provided in the component configuration (component_info$config$click_handler), it will be called with the DT proxy, selected data (or NULL for deselection), and session. Otherwise, default row selection/deselection is performed.

Examples

if (FALSE) { # \dontrun{
# Update DT selection when ID "123" is selected
update_dt_selection("my_table", "123", session, components)

# Deselect all rows
update_dt_selection("my_table", NULL, session, components)
} # }