A virtualised table for data frames or lazy table sources. See data_table().
Super class
Widget -> DataTable
Public fields
paint_statesCursor and scroll changes only repaint.
focusableTables can be focused.
cursor_type"row","cell"or"none".show_headerShow the header row?
zebraStripe alternate rows?
row_styleNULLorfunction(row, data)returning a style for a data row (rowis the original row number or source position).cell_styleNULLorfunction(value, row, column)returning a style for a cell.frozen_columnsNumber of leading columns that stay visible while the others scroll horizontally.
header_sortClicking a header sorts by that column (click again: descending, then unsorted; Shift+click adds a column)?
editableAllow editing cells (Enter / double click)?
on_editNULLorfunction(row, column, value)called before a cell edit is applied; returnNULL/TRUEto accept or a message to reject the edit.
Active bindings
dataThe data frame or source (assigning calls
set_data()).row_countNumber of rows in the current view.
column_namesNames of the data columns.
cursor_rowCursor position in the view (0 = none).
cursor_columnCursor column number (cell cursor; 0 = none).
offset_row, offset_columnScroll offsets (rows / columns).
viewRow numbers or source view positions in display order.
sort_stateNULLor a data frame (column,decreasing) of the current sort keys.match_hitNULLor the current search result (position,row,column).
Methods
Inherited methods
Widget$add_class()Widget$ancestors()Widget$animate()Widget$arrange_children()Widget$bind()Widget$bind_reactive()Widget$bindings()Widget$blur()Widget$capture_mouse()Widget$child_clip()Widget$clear()Widget$computed_style()Widget$focus()Widget$format()Widget$get_state()Widget$has_class()Widget$invalidate()Widget$invalidate_paint()Widget$is_displayed()Widget$is_enabled()Widget$layout_descend()Widget$layout_differs()Widget$matches()Widget$mount()Widget$on()Widget$post_message()Widget$print()Widget$pseudo_states()Widget$query()Widget$query_one()Widget$release_mouse()Widget$remove()Widget$remove_children()Widget$remove_class()Widget$render()Widget$render_lines()Widget$replace()Widget$run_action()Widget$run_process()Widget$run_worker()Widget$set()Widget$set_interval()Widget$set_state()Widget$set_timeout()Widget$toggle_class()Widget$walk()
DataTable$new()
Create a table. See data_table().
Usage
DataTable$new(
data,
cursor = "row",
columns = NULL,
formatters = NULL,
row_names = NA,
header = TRUE,
zebra = FALSE,
row_style = NULL,
cell_style = NULL,
max_column_width = 40L,
frozen_columns = 0L,
header_sort = FALSE,
editable = FALSE,
on_edit = NULL,
id = NULL,
classes = NULL,
style = NULL,
disabled = FALSE
)Arguments
dataA data frame, matrix, or
table_source().cursorCursor type.
columnsNamed list of
column()options.formattersNamed list of formatter functions.
row_namesShow row names?
NA: only when they are not 1..n.headerShow the header?
zebraStripe rows?
row_style, cell_styleStyle hooks.
max_column_widthUpper limit for estimated widths.
frozen_columns, header_sort, editable, on_editSee the fields.
id, classes, style, disabledSee Widget.
filtersNamed column filters for
filter_columns().
DataTable$set_data()
Replace the data. Resets the view, cursor and scroll.
Arguments
dataA data frame, matrix, or
table_source().
DataTable$sort()
Sort the view by one or more columns (stable; NAs
last). Sorting always starts from the unsorted view (after
filter()), so sort(c("cyl", "mpg")) sorts by cyl, then mpg.
DataTable$toggle_sort()
Header-click behaviour: sort by a column ascending, then descending, then unsorted.
DataTable$filter_columns()
Filter named columns; all predicates are combined with
AND and evaluated in row chunks. A predicate may be a
table_filter() or function(values) logical.
DataTable$selected_data()
Data for selected view rows, in view order. A single cursor row is returned when no range is selected.
DataTable$set_column_width()
Set a column's width (at least 1 cell). Sends
"datatable.column_resized".
DataTable$auto_size_column()
Fit a column to its content. Rows are sampled, never all scanned unless asked for, so this is fast for huge tables.
Usage
DataTable$auto_size_column(column, rows = c("sample", "visible", "all"))DataTable$auto_size_all()
Fit every visible column to its content.
Usage
DataTable$auto_size_all(rows = c("sample", "visible", "all"))DataTable$find()
Search the formatted cell text and move the cursor to the first match at or after the cursor (reading order, wrapping around). Large tables are scanned in chunks; the data is never converted to one big string matrix.
DataTable$edit_cell()
Edit a cell in a small dialog (needs editable = TRUE).
The default is the cursor cell.
DataTable$set_cell()
Change one cell of the table's own copy of the data
(the data frame you passed in is never modified; read the result
with $data). Runs on_edit, then sends "datatable.cell_changed"
with row, column, old and value.
DataTable$action_activate()
Send "datatable.row_activated" for the cursor row
(or edit the cell when the table is editable).
DataTable$on_mouse_down()
Mouse: clicking a row moves the cursor, clicking the
header sends "datatable.header_selected" (and sorts when
header_sort is on); dragging a column separator in the header
resizes the column; a double click edits a cell of an editable table.
DataTable$paint()
Draw the visible part of the table.
Arguments
bufferA ScreenBuffer.
areaVisible part of the region.
stComputed style.