Skip to contents

Create interactive tables : sortable, filterable, editable with the JavaScript library tui-grid.

Usage

datagrid(
  data = list(),
  ...,
  sortable = TRUE,
  pagination = NULL,
  filters = FALSE,
  colnames = NULL,
  colwidths = "fit",
  align = "auto",
  theme = c("clean", "striped", "default"),
  draggable = FALSE,
  data_as_input = FALSE,
  contextmenu = FALSE,
  datepicker_locale = NULL,
  guess_colwidths_opts = guess_colwidths_options(),
  width = NULL,
  height = NULL,
  elementId = NULL
)

Arguments

data

A data.frame or something convertible in data.frame.

...

Arguments passed to the Grid JavaScript method.

sortable

Logical, allow to sort columns.

pagination

Number of rows per page to display, default to NULL (no pagination).

filters

Logical, allow to filter columns.

colnames

Alternative colnames to be displayed in the header.

colwidths

Width for the columns, can be "auto" (width is determined by column's content) or a single or numeric vector to set the width in pixel. Use NULL to disable and use default behavior.

align

Alignment for columns content: "auto" (numeric and date on right, other on left), "right", "center" or "left". Use NULL to ignore.

theme

Predefined theme to be used.

draggable

Whether to enable to drag the row for changing the order of rows.

data_as_input

Should the data be available in an input input$<ID>_data server-side?

contextmenu

Display or not a context menu when using right click in the grid. Can also be a list of custom options, see tui-grid documentation for examples.

datepicker_locale

Custome locale texts for datepicker editor, see example in grid_editor_date().

guess_colwidths_opts

Options when colwidths = "guess", see guess_colwidths_options().

width, height

Width and height of the table in a CSS unit or a numeric.

elementId

Use an explicit element ID for the widget.

Value

A datagrid htmlwidget.

See also

datagridOutput() / renderDatagrid() for usage in Shiny applications.

Examples

library(toastui)

# default usage
datagrid(rolling_stones_50)
# Column's width alternatives (default is "fit") datagrid(rolling_stones_50, colwidths = "guess")
datagrid(rolling_stones_50, colwidths = "auto")
datagrid(rolling_stones_50, colwidths = NULL)
# disable sorting datagrid(rolling_stones_50, sortable = FALSE)
# enable default filtering datagrid(rolling_stones_50, filters = TRUE)
# enable pagination (10 rows per page) datagrid(rolling_stones_50, pagination = 10)
# Themes datagrid(rolling_stones_50, theme = "striped")
datagrid(rolling_stones_50, theme = "default")
# Empty table datagrid(list())
# Empty columns datagrid(data.frame( variable_1 = character(0), variable_2 = character(0) ))
# Specify colnames datagrid( data = data.frame( variable_1 = sample(1:50, 12), variable_2 = month.name ), colnames = c("Number", "Month of the year") )