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).- 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.
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)
)
})
} # }