-
Notifications
You must be signed in to change notification settings - Fork 184
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
Timezone in Filter #241
Comments
Good question. For now it is not possible to specify timezone information but I'll consider it in the future. Thanks! |
Hi, I have same issue, How can I resolve this? Filter TZ x Column TZ? library(DT)
df_Time <- data.frame(date = seq.POSIXt(Sys.time(), by="-1 hour", length.out=20))
df_Time$date2 <- as.POSIXct(strptime(df_Time$date,"%Y-%m-%d %H:%M:%S"), "America/Sao_Paulo")
datatable(df_Time, filter = "top",
rownames = FALSE,
selection = "none",
caption = "Execuções Banco de Dados",
extensions = c('Buttons','ColReorder'),
options = list(colReorder = TRUE,
dom = 'ltBip',
align = "right",
buttons = c('copy', 'csv', 'excel', 'pdf')
)) %>% formatDate(c(1,2), method = 'toLocaleString') |
Hi, I'm also facing this issue. Any news regarding this? |
@ismirsehregal I'll take a look in the weekend to see if I can help or not. |
That would be great! |
You can try the development version now: devtools::install_github('rstudio/DT') |
Hi,
But their default behavior doesn’t meet my desired output.
I guess it’s possible to adapt the output with the “params” argument of the formatDate function but I couldn’t create the format shown in the “desired”-column – maybe you can give me another push in the right direction? |
library(DT)
library(data.table)
timestamps <- as.POSIXct("2018-04-13 07:51:19", tz = "CET") - 0:4
DTable <-
data.table(
timestamp = timestamps,
formatDate = timestamps,
desired = paste(as.character(timestamps), "CEST")
)
tmp <- DT::datatable(
DTable,
filter = 'top') %>%
formatDate(
"formatDate",
method = 'toLocaleString',
params = list(
"se",
list(timeZone = "Europe/Oslo", hour12 = FALSE) # see the comment below
)
)
######### THE HACKING ###################################3
tmp$x$options$rowCallback <- JS('
function(row, data) {
var col = 2;
var d = data[col];
if (d === null) return;
d = new Date(d);
$(this.api().cell(row, col).node()).html(d[\'toLocaleString\'].apply(d, ["se",{"timeZone":"Europe/Oslo","hour12":false}]) + " CEST");
}')
##########################################################
tmp |
You may ask why I use |
Thanks for all the input! Accordingly, my control concerning the actual output seems quite limited, so I’ll simply stick with the default behavior of ‘toLocaleString’. So once again thank you for your time and effort. BR |
Hi there,
I am new to DT and I am trying to figure out how to set time zone in the filter for a datatable in a Shiny app. The table has a column of time stamps. I'd like it to be in US/Central and it seems to work well in the table. However the filter is shown in UTC.
Here is an example:
The text was updated successfully, but these errors were encountered: