knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
dtsmartr supports modern, spreadsheet-like multi-column sorting natively by interacting with column headers.
Clicking directly anywhere on a column header card triggers sorting:
- First Click: Sorts the column ascending (↑).
- Second Click: Sorts the column descending (↓).
- Third Click: Clears the sort state for that column.
To sort by multiple columns sequentially (e.g., sort by cyl first, then by mpg within each cylinder class):
- Click the first column header (e.g., cyl) to set the primary sort.
- Hold Shift and click the second column header (e.g., mpg) to append it to the sort chain.
- The UI displays numbered emoji badges (e.g., 1️⃣ ↑, 2️⃣ ↓) next to the column names to show the sorting priority and direction.
- The active sort chain is also printed in the grid's top toolbar (e.g., ↕ cyl asc (1) -> mpg desc (2)).
Shift + Click the sorted column header until its sort direction indicator disappears.Try sorting by cylinders (cyl) first, and then sorting by miles-per-gallon (mpg) inside the cylinder groups:
library(dtsmartr) dtsmartr(mtcars)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.