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

Fix for interactive tables with hidden columns within spanners #1629

Merged
merged 11 commits into from
Apr 27, 2024
25 changes: 21 additions & 4 deletions R/render_as_i_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ render_as_ihtml <- function(data, id) {

default_col_def <-
reactable::colDef(
style = reactable::JS(body_style_js_str)
style = reactable::JS(body_style_js_str),
minWidth = 125,
width = NULL
)

# Generate the table header if there are any heading components
Expand Down Expand Up @@ -347,7 +349,18 @@ render_as_ihtml <- function(data, id) {
colgroups_def <- NULL

if (has_tab_spanners) {
col_groups <- (dt_spanners_get(data = data) %>% dplyr::filter(spanner_level == 1))

hidden_columns <- dt_boxhead_get_var_by_type(data = data, type = "hidden")
col_groups <- dplyr::filter(dt_spanners_get(data = data), spanner_level == 1)

for (i in seq_len(nrow(col_groups))) {

columns_group_i <- unlist(col_groups[i, ][["vars"]])

columns_group_i_diff <- base::setdiff(columns_group_i, hidden_columns)

col_groups[i, ][["vars"]][[1]] <- columns_group_i_diff
}

if (max(dt_spanners_get(data = data)$spanner_level) > 1) {
first_colgroups <- base::paste0(col_groups$built, collapse = "|")
Expand Down Expand Up @@ -377,8 +390,12 @@ render_as_ihtml <- function(data, id) {
borderBottomStyle = column_labels_border_bottom_style,
borderBottomWidth = column_labels_border_bottom_width,
borderBottomColor = column_labels_border_bottom_color,
marginLeft = "4px",
marginRight = "4px"
borderLeftStyle = column_labels_border_bottom_style,
borderLeftWidth = "4px",
borderLeftColor = "transparent",
borderRightStyle = column_labels_border_bottom_style,
borderRightWidth = "4px",
borderRightColor = "transparent"
)
)
}
Expand Down
Loading