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)
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
# Column's width alternatives (default is "fit") datagrid(rolling_stones_50, colwidths = "guess")
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
datagrid(rolling_stones_50, colwidths = "auto")
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
2
1966
Pet Sounds
The Beach Boys
3
1966
Revolver
The Beatles
4
1965
Highway 61 Revisited
Bob Dylan
5
1965
Rubber Soul
The Beatles
6
1971
What's Going On
Marvin Gaye
7
1972
Exile on Main St.
The Rolling Stones
8
1979
London Calling
The Clash
9
1966
Blonde on Blonde
Bob Dylan
10
1968
The Beatles (""The White Album"")
The Beatles
datagrid(rolling_stones_50, colwidths = NULL)
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
# disable sorting datagrid(rolling_stones_50, sortable = FALSE)
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
# enable default filtering datagrid(rolling_stones_50, filters = TRUE)
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
# enable pagination (10 rows per page) datagrid(rolling_stones_50, pagination = 10)
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
firstprev12345nextlast
# Themes datagrid(rolling_stones_50, theme = "striped")
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
datagrid(rolling_stones_50, theme = "default")
NumberYearAlbumArtistGenreSubgenre
1
1967
Sgt. Pepper's Lonely Hearts Club Band
The Beatles
Rock
Rock & Roll, Psychedelic Rock
2
1966
Pet Sounds
The Beach Boys
Rock
Pop Rock, Psychedelic Rock
3
1966
Revolver
The Beatles
Rock
Psychedelic Rock, Pop Rock
4
1965
Highway 61 Revisited
Bob Dylan
Rock
Folk Rock, Blues Rock
5
1965
Rubber Soul
The Beatles
Rock, Pop
Pop Rock
6
1971
What's Going On
Marvin Gaye
Funk / Soul
Soul
7
1972
Exile on Main St.
The Rolling Stones
Rock
Blues Rock, Rock & Roll, Classic Rock
8
1979
London Calling
The Clash
Rock
Punk, New Wave
9
1966
Blonde on Blonde
Bob Dylan
Rock, Blues
Folk Rock, Rhythm & Blues
10
1968
The Beatles (""The White Album"")
The Beatles
Rock
Rock & Roll, Pop Rock, Psychedelic Rock, Experimental
# Empty table datagrid(list())

No data.

# Empty columns datagrid(data.frame( variable_1 = character(0), variable_2 = character(0) ))
variable_1variable_2

No data.

# Specify colnames datagrid( data = data.frame( variable_1 = sample(1:50, 12), variable_2 = month.name ), colnames = c("Number", "Month of the year") )
NumberMonth of the year
15
January
38
February
27
March
43
April
9
May
7
June
45
July
20
August
44
September
41
October