Skip to content

Allows custom column filter placeholder #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions R/datatables.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
#' columns and the text areas for some other columns by setting
#' \code{editable} to a list of the form \code{list(target = TARGET, numeric
#' = INDICES1, area = INDICES2)}.
#' @param columnFilterPlaceholder a length-one character vector to specify the
#' placeholder text for the column filter input boxes. Defaults to
#' \code{"All"}.
#' @details \code{selection}:
#' \enumerate{
#' \item The argument could be a scalar string, which means the selection
Expand Down Expand Up @@ -176,7 +179,7 @@ datatable = function(
fillContainer = getOption('DT.fillContainer', NULL),
autoHideNavigation = getOption('DT.autoHideNavigation', NULL),
selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL,
editable = FALSE
editable = FALSE, columnFilterPlaceholder = 'All'
) {

# yes, we all hate it
Expand Down Expand Up @@ -281,7 +284,7 @@ datatable = function(
if (is.character(filter)) filter = list(position = match.arg(filter))
filter = modifyList(list(position = 'none', clear = TRUE, plain = FALSE, vertical = FALSE, opacity = 1), filter)
# HTML code for column filters
filterHTML = as.character(filterRow(data, !is.null(rn) && colnames[1] == ' ', filter))
filterHTML = as.character(filterRow(data, !is.null(rn) && colnames[1] == ' ', filter, placeholder = columnFilterPlaceholder))
# use the first row in the header as the sorting cells when I put the filters
# in the second row
if (filter$position == 'top') options$orderCellsTop = TRUE
Expand Down Expand Up @@ -630,12 +633,13 @@ tableHead = function(names, type = c('head', 'foot'), escape = TRUE, ...) {

filterRow = function(
data, rownames = TRUE,
filter = list(position = 'none', clear = TRUE, plain = FALSE, vertical = FALSE, opacity = 1)
filter = list(position = 'none', clear = TRUE, plain = FALSE, vertical = FALSE, opacity = 1),
placeholder = 'All'
) {
if (filter$position == 'none') return()

filters = columnFilters(data)
row = columnFilterRow(filters, options = filter)
row = columnFilterRow(filters, options = filter, placeholder = placeholder)

# no filter for row names (may change in future)
if (rownames) {
Expand Down Expand Up @@ -721,7 +725,7 @@ columnFilters = function(data) {
}

#' @importFrom htmltools tagList
columnFilterRow = function(filters, options = list()) {
columnFilterRow = function(filters, options = list(), placeholder = 'All') {
defaults = list(clear = TRUE, plain = FALSE, vertical = FALSE, opacity = 1)
options = modifyList(defaults, options)

Expand Down Expand Up @@ -759,7 +763,7 @@ columnFilterRow = function(filters, options = list()) {
tags$div(
style = 'margin-bottom: auto;',
tags$input(
type = if (clear) 'search' else 'text', placeholder = 'All',
type = if (clear) 'search' else 'text', placeholder = placeholder,
style = 'width: 100%;',
disabled = if (f$disabled) ""
)
Expand All @@ -769,7 +773,7 @@ columnFilterRow = function(filters, options = list()) {
class = if (clear) 'form-group has-feedback' else 'form-group',
style = 'margin-bottom: auto;',
tags$input(
type = 'search', placeholder = 'All', class = 'form-control',
type = 'search', placeholder = placeholder, class = 'form-control',
style = 'width: 100%;',
disabled = if (f$disabled) ""
),
Expand Down
14 changes: 7 additions & 7 deletions man/coerceValue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dataTableAjax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dataTableOutput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/datatable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/doColumnSearch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/formatCurrency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.