A DataGrid component with server-side pagination, sorting, and filtering. The component sends pagination, sort, and filter state to R via a Shiny input.
Usage
DataGridServer(
inputId,
rows = NULL,
columns = NULL,
rowCount = NULL,
loading = NULL,
initialPageSize = NULL,
pageSizeOptions = NULL,
filterDebounce = NULL,
...
)Arguments
- inputId
Character. The Shiny input ID. When pagination, sorting, or filtering changes, the new state is available as
input$<inputId>in the server. The value is a list with elementspagination_model(list withpageandpageSize),sort_model(list of sort items), andfilter_model(list withitems).- rows
A data.frame. Pass the full dataset (like
DataGrid()) and letDataGridServer()handle pagination automatically, or pass a pre-sliced page together with an explicitrowCountfor manual control.- columns
Column definitions (list of lists). If NULL, auto-generated from
names(rows), with each column'stypeinferred from its R class (seeDataGrid).- rowCount
Integer. When provided,
rowsis assumed to be already paginated androwCountis used as the total row count (manual mode). WhenNULL(default), pagination is handled automatically from the fullrowsdataset.- loading
Logical. Whether to show the loading indicator. If
NULL, MUI defaults toFALSE.- initialPageSize
Integer. Convenience for setting the initial page size. Builds MUI's
initialStateprop. IfNULL, MUI defaults to 100. Also sets the page size for the first automatic render before the grid has sent state. Must be included inpageSizeOptions.- pageSizeOptions
Integer vector. Available page size options. If
NULL, MUI defaults toc(25, 50, 100).- filterDebounce
Integer. Milliseconds to debounce filter input before sending state to R. If
NULL, defaults to 300 ms.- ...
Additional props passed directly to the MUI DataGrid component. Note:
paginationMode,sortingMode,filterMode, andpaginationare set automatically and should not be overridden.
Details
Pass the full dataset via rows — just like DataGrid() —
and DataGridServer() handles pagination, sorting, and filtering
automatically. For manual control (e.g. database queries), supply
pre-sliced rows together with an explicit rowCount.
Lifecycle
Experimental. DataGridServer() (together with
processGridParams) is specific to this R package and has
no equivalent in MUI X Data Grid: MUI ships only the building blocks
(paginationMode = "server" plus callbacks) and leaves the data layer
to you. This wrapper supplies that layer in R, and in doing so encodes a
number of opinionated decisions that may change in future releases. Pin the
package version if you rely on the current behaviour. Decisions worth
knowing about:
Mode is selected by the presence of
rowCount: supply it to pass a pre-sliced page (manual mode); omit it to let the fullrowsbe paginated automatically.Changing the sort or any filter resets the grid to the first page.
Unrecognised filter operators pass all rows through with a warning (see
processGridParams).When
rowshas noidcolumn, ids are generated positionally and are not stable across sort/filter changes. Supply a stable, uniqueidcolumn if you use row selection.
Examples
if (FALSE) { # \dontrun{
# Simple usage: pass the full dataset, pagination is handled automatically
output$grid <- renderReact({
DataGridServer("grid_params",
rows = my_data,
initialPageSize = 10L,
pageSizeOptions = c(10L, 25L, 50L)
)
})
# Manual usage: handle pagination yourself (e.g. database queries)
output$grid <- renderReact({
result <- processGridParams(my_data, input$grid_params, pageSize = 10L)
DataGridServer("grid_params",
rows = result$rows,
rowCount = result$rowCount,
initialPageSize = 10L,
pageSizeOptions = c(10L, 25L, 50L)
)
})
} # }