datatable_EZ: A friendly version of 'DT::datatable()'

Description Usage Arguments Value References See Also Examples

View source: R/datatable_EZ.R

Description

This is a wrapper around DT::datatable() with more convenient defaults. Also, most common elements of options() argument are moved to direct arguments list for this function. This removes the necessity to pass on a long options list (which is not fully documented in the DT package documentation). It also exposes them auto-complete drop-downs in RStudio IDE.

Usage

1
2
3
4
5
6
datatable_EZ(data, colnames, filter = "none", caption = NULL,
  rownames = FALSE, class = "compact display", dom = "lftip",
  font_family = "Arial", font_size = 10, font_size_header = font_size + 2,
  pageLength = 10, lengthMenu = c(5, 10, 25, 50, 100, 500),
  searchHighlight = TRUE, columnDefs = list(), col_widths = NULL,
  ordering = TRUE, order = list(), options = list(), ...)

Arguments

data

a data object (either a matrix or a data frame)

colnames

if missing, the column names of the data; otherwise it can be an unnamed character vector of names you want to show in the table header instead of the default data column names; alternatively, you can provide a named numeric or character vector of the form 'newName1' = i1, 'newName2' = i2 or c('newName1' = 'oldName1', 'newName2' = 'oldName2', ...), where newName is the new name you want to show in the table, and i or oldName is the index of the current column name

filter

whether/where to use column filters; none: no filters; bottom/top: put column filters at the bottom/top of the table; range sliders are used to filter numeric/date/time columns, select lists are used for factor columns, and text input boxes are used for character columns; if you want more control over the styles of filters, you can provide a list to this argument of the form list(position = 'top', clear = TRUE, plain = FALSE), where clear indicates whether you want the clear buttons in the input boxes, and plain means if you want to use Bootstrap form styles or plain text input styles for the text input boxes

caption

the table caption; a character vector or a tag object

rownames

TRUE (show row names) or FALSE (hide row names) or a character vector of row names; by default, the row names are not shown

class

the CSS class(es) of the table, defaults to "compact display"; see http://datatables.net/manual/styling/classes

dom

By default, the table has these DOM elements: the length-(l) menu, the filtering-(f) input box, the table-(t), the information-(i) summary, and the pagination-(p) control. You can choose to display a subset of these elements. See https://datatables.net/reference/option/dom for details.

font_family, font_size, font_size_header

control how the table's fonts are rendered in the browser. The default font family is 'Arial' 12 'pt' data cells and 14 'pt' for headers.

pageLength

a number of records to be displayed per page when the table loads

lengthMenu

a numeric vector of page length drop-down options

searchHighlight

a logical; should search expression be highlighted? Defaults to TRUE

columnDefs

list of column definitions; see Examples.

col_widths

An numeric vector of column widths, in pixels. Must equal the number of columns in the data. Ignored if columnDefs is specified.

ordering

logical; should the table be sortable?

order

list of row sorting options; see examples.

options

a list() of all other options.

...

all other arguments passed to DT::datatable()

Value

DT::datatable object

References

See http://rstudio.github.io/DT for the full documentation.

See Also

datatable, format_databars

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(DT)

# original DT::datatable
datatable(iris)
# no rownumbers by default
datatable_EZ(iris)

# individual option arguments
datatable_EZ(
    iris,
    # DOM elements (table only)
    dom="t",
    # column definitions
    columnDefs = list(list(width = '50px', targets = c(1, 3))),
    # Row Sorting
    order = list(list(0, 'desc'), list(1, 'asc'))
)

# specify column widths in pixels
datatable_EZ(
    iris,
    col_widths = c(50, 50, 300, 50, 300)
)

# disable sorting and searching by user ("static version")
datatable_EZ(iris, ordering = FALSE, dom = "t")


# Pagination
datatable_EZ(mtcars, pageLength = 3, lengthMenu = c(3,5,10))

vadimus202/datatableEZ documentation built on May 3, 2019, 2:41 p.m.