Skip to content

Add the row_order() function#2099

Merged
rich-iannone merged 18 commits intomasterfrom
order-within-groups
Jan 14, 2026
Merged

Add the row_order() function#2099
rich-iannone merged 18 commits intomasterfrom
order-within-groups

Conversation

@rich-iannone
Copy link
Copy Markdown
Member

@rich-iannone rich-iannone commented Jan 14, 2026

This PR adds the row_order() function and it lets you modify the display order of rows within any row groups (or across the entire table). One or more column names can be provided to define the sorting criteria. Here's an example:

gtcars |>
  dplyr::select(mfr, model, ctry_origin, msrp) |>
  dplyr::filter(ctry_origin %in% c("Japan", "United Kingdom")) |>
  dplyr::slice_head(n = 12) |>
  gt(groupname_col = "ctry_origin") |>
  row_order(msrp, reverse = TRUE) |>
  fmt_currency(columns = msrp, decimals = 0) |>
  tab_options(column_labels.hidden = TRUE)
man_row_order_1

The ordering can also be constrained to named groups:

towny |>
  dplyr::filter(csd_type %in% c("city", "town", "township")) |>
  dplyr::select(name, csd_type, population_2021, density_2021) |>
  dplyr::slice_head(n = 5, by = csd_type) |>
  gt(groupname_col = "csd_type") |>
  fmt_integer(columns = population_2021) |>
  fmt_number(columns = density_2021, decimals = 1) |>
  row_order(density_2021, groups = c("city", "town"), reverse = TRUE)
man_row_order_2

Fixes: #1112

@rich-iannone rich-iannone merged commit 0f48a9a into master Jan 14, 2026
12 checks passed
@rich-iannone rich-iannone deleted the order-within-groups branch January 14, 2026 16:05
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 this pull request may close these issues.

Enable ability to specify order of rows **within** a group

1 participant