Skip to content

Commit

Permalink
grid_editor_date() new arguments language and weekStartDay.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Mar 1, 2024
1 parent 638c65f commit a0e0432
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 19 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# toastui 0.3.2

* Updated tui-grid to 4.21.22.
* `grid_editor_date()` new arguments `language` and `weekStartDay`.

### Breaking changes

Expand Down
5 changes: 4 additions & 1 deletion R/datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @param contextmenu Display or not a context menu when using right click in the grid.
#' Can also be a list of custom options, see [tui-grid documentation](https://nhn.github.io/tui.grid/latest/tutorial-example27-export/)
#' for examples.
#' @param datepicker_locale Custome locale texts for datepicker editor, see example in [grid_editor_date()].
#' @param width,height Width and height of the table in a CSS unit or a numeric.
#' @param elementId Use an explicit element ID for the widget.
#'
Expand All @@ -44,6 +45,7 @@ datagrid <- function(data = list(),
draggable = FALSE,
data_as_input = FALSE,
contextmenu = FALSE,
datepicker_locale = NULL,
width = NULL,
height = NULL,
elementId = NULL) {
Expand Down Expand Up @@ -120,7 +122,8 @@ datagrid <- function(data = list(),
updateEditOnClick = NULL,
validationInput = FALSE,
dataAsInput = data_as_input,
dragInput = isTRUE(draggable)
dragInput = isTRUE(draggable),
datepicker_locale = datepicker_locale
))

# create widget
Expand Down
8 changes: 6 additions & 2 deletions R/grid-editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ validateOpts <- function(required = NULL,
#' @param format Date format, default is \code{"yyyy-MM-dd"}.
#' @param type Type of selection: date, month or year.
#' @param timepicker Add a timepicker.
#' @param weekStartDay Start of the week : 'Sun' (default), 'Mon', ..., 'Sat'
#' @param language Either `"en"` or `"ko"` the builtin language, or `"custom"` to use texts defined in `datagrid(datepicker_locale = list(...))`, see example.
#'
#' @return A `datagrid` htmlwidget.
#' @export
Expand All @@ -178,11 +180,13 @@ grid_editor_date <- function(grid,
column,
format = "yyyy-MM-dd",
type = c("date", "month", "year"),
timepicker = c("none", "tab", "normal")) {
timepicker = c("none", "tab", "normal"),
weekStartDay = NULL,
language = NULL) {
check_grid(grid, "grid_editor")
type <- match.arg(type)
timepicker <- match.arg(timepicker)
options <- list(format = format)
options <- dropNulls(list(format = format, language = language, weekStartDay = weekStartDay))
if (type %in% c("month", "year")) {
options$type <- type
}
Expand Down
36 changes: 29 additions & 7 deletions examples/ex-grid_editor_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,56 @@ library(toastui)

dat <- data.frame(
date = Sys.Date() + 1:10,
date_locale = format(Sys.Date() + 1:10, format = "%d/%m/%Y"),
month = format(Sys.Date() + 1:10, format = "%Y-%m"),
year = format(Sys.Date() + 1:10, format = "%Y"),
time1 = Sys.time() + 1:10,
time2 = Sys.time() + 1:10
)


datagrid(dat) %>%
datagrid(
data = dat,
datepicker_locale = list(
titles = list(
DD = c("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"),
D = c("Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"),
MMMM = c("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet",
"Août", "Septembre", "Octobre", "Novembre", "Décembre"),
MMM = c("Jan", "Fév", "Mar", "Avr", "Mai", "Juin", "Juil", "Aou", "Sept", "Oct", "Nov", "Déc")
),
titleFormat = "MMM yyyy",
todayFormat = "DD dd MMMM yyyy",
date = "Date",
time = "Heure"
)
) %>%
grid_editor_date(
column = "date"
) %>%
)%>%
grid_editor_date(
column = "date_locale",
format = "dd/MM/yyyy",
language = "custom",
weekStartDay = "Mon"
) %>%
grid_editor_date(
column = "month",
type = "month",
format = "yyyy-MM"
) %>%
) %>%
grid_editor_date(
column = "year",
type = "year",
format = "yyyy"
) %>%
) %>%
grid_editor_date(
column = "time1",
column = "time1",
timepicker = "tab",
format = "yyyy-MM-dd HH:mm"
) %>%
) %>%
grid_editor_date(
column = "time2",
column = "time2",
timepicker = "normal",
format = "yyyy-MM-dd HH:mm"
)
2 changes: 1 addition & 1 deletion inst/htmlwidgets/datagrid.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions man/datagrid.Rd

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

44 changes: 36 additions & 8 deletions man/grid_editor_date.Rd

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

5 changes: 5 additions & 0 deletions srcjs/widgets/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "tui-grid/dist/tui-grid.min.css";
import "tui-pagination/dist/tui-pagination.css";
import "tui-date-picker/dist/tui-date-picker.css";
import "tui-time-picker/dist/tui-time-picker.css";
import TuiDatePicker from "tui-date-picker";

import { ProxyGrid } from "../modules/proxy-grid";
import { addStyle } from "../modules/utils";
Expand Down Expand Up @@ -69,6 +70,10 @@ HTMLWidgets.widget({

var rowAttributes = x.rowAttributes;

if (config.hasOwnProperty("datepicker_locale")) {
TuiDatePicker.localeTexts["custom"] = config.datepicker_locale;
}

//if (options.hasOwnProperty("bodyHeight") & HTMLWidgets.shinyMode) {
// if (options.bodyHeight == "fitToParent") {
// document.getElementById(el.id).style.marginBottom = "25px";
Expand Down

0 comments on commit a0e0432

Please sign in to comment.