Skip to contents

For tables people search, page through, and click: search results, item lists to edit. Same look as kit_static_table(): 2px frame, black header with white text, zebra stripes, small type, numbers right-aligned; a selected row is light lime (bg-new), not blue. Text is in Traditional Chinese ("共 37 列,第 1–20 列", "上一頁", "下一頁"); the page buttons look like small buttons. Width fits the content; on a phone a wide table scrolls sideways inside its own box, never the page.

Usage

kit_dt(
  df,
  selection = "none",
  page_length = 20L,
  search = FALSE,
  wrap_cols = NULL,
  min_widths = NULL,
  ordering = TRUE,
  options = list(),
  ...
)

Arguments

df

A data.frame. Column names stay as they are (data and function output keep their English names).

selection

"none", "single", or "multiple" (click to select rows). A list is passed to DT::datatable(selection = ) as it is (for example with selected = ).

page_length

Rows per page. 0 shows all rows (no paging).

Show the table's own search box. Usually FALSE: the page has its own conditions.

wrap_cols

Columns whose long text wraps (for example the item text); other columns do not wrap.

min_widths

Named vector of minimum column widths in CSS units, for example c(label = "24rem").

ordering

Click the header to sort.

options

More DataTables options (override the defaults). columnDefs given here come first, so they win over the ones kit_dt() makes.

...

Passed to DT::datatable().

Value

A datatables htmlwidget with class kit-dt.

Details

Use it inside DT::renderDT(). 'DT' is in Suggests: the app itself needs Imports: DT. For short result tables that need no paging, use kit_static_table().

See also

kit_static_table() for short result tables, kit_table_scroll().

Examples

if (requireNamespace("DT", quietly = TRUE)) {
  kit_dt(data.frame(itemID = c("a1", "a2"), label = c("睡眠時間", "午睡")),
         selection = "single", wrap_cols = "label")
}