diff --git a/R/columns.R b/R/columns.R index 1128f70..c74ed77 100644 --- a/R/columns.R +++ b/R/columns.R @@ -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 diff --git a/examples/formatters/formatter_datetime.R b/examples/formatters/formatter_datetime.R new file mode 100644 index 0000000..43c949d --- /dev/null +++ b/examples/formatters/formatter_datetime.R @@ -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") diff --git a/man/set_formatter_datetime.Rd b/man/set_formatter_datetime.Rd new file mode 100644 index 0000000..64a551c --- /dev/null +++ b/man/set_formatter_datetime.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/columns.R +\name{set_formatter_datetime} +\alias{set_formatter_datetime} +\title{Datetime formatter} +\usage{ +set_formatter_datetime( + widget, + column, + input_format = "yyyy-MM-dd hh:ss:mm", + output_format = "yy/MM/dd", + invalid_placeholder = "(invalid datetime)", + timezone = NA +) +} +\arguments{ +\item{widget}{(\code{\link{tabulator}}) A tabulator widget.} + +\item{column}{(character): The column the formatter is applied to.} + +\item{input_format}{(character): The datetime input format.} + +\item{output_format}{(character): The datetime output format.} + +\item{timezone}{(character): The timezone of the datetime.} +} +\description{ +Datetime formatter +} +\examples{ +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") +}