Skip to content

Commit

Permalink
Add datetime example
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 12, 2024
1 parent 25e4d64 commit f2db08e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
27 changes: 25 additions & 2 deletions R/columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,32 @@ set_formatter_toggle_switch <- function(
modify_col_def(widget, column, col_update)
}

#' Datetime formatter
#' @inheritParams set_formatter_html
#' @param input_format (character): The datetime input format.
#' @param output_format (character): The datetime output format.
#' @param timezone (character): The timezone of the datetime.
#' @example examples/formatters/formatter_datetime.R
#' @export
set_formatter_datetime <- function(widget, column) {

set_formatter_datetime <- function(
widget,
column,
input_format = "yyyy-MM-dd hh:ss:mm",
output_format = "yy/MM/dd",
invalid_placeholder = "(invalid datetime)",
timezone = NA
) {
# Body
col_update <- list(
formatter = "datetime",
formatterParams = list(
inputFormat = input_format,
outputFormat = output_format,
invalidPlaceholder = invalid_placeholder,
timezone = timezone
)
)
modify_col_def(widget, column, col_update)
}

#' Color Formatter
Expand Down
10 changes: 10 additions & 0 deletions examples/formatters/formatter_datetime.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data <- data.frame(
Person = c("Franz", "Ferdinand"),
Birthday =c(
"2024-12-06 22:00:10",
"2023-06-07 14:12:45"
)
)

tabulator(data) |>
set_formatter_datetime("Birthday", output_format = "dd.MM.yyyy")
41 changes: 41 additions & 0 deletions man/set_formatter_datetime.Rd

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

0 comments on commit f2db08e

Please sign in to comment.