diff --git a/R/datatables.R b/R/datatables.R index 21ffc6af..2e69b5fa 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -66,6 +66,7 @@ #' extensions (\url{https://datatables.net/extensions/index}) #' @param plugins a character vector of the names of DataTables plug-ins #' (\url{https://rstudio.github.io/DT/plugins.html}) +#' @param editable \code{TRUE} to enable table editor. #' @note You are recommended to escape the table content for security reasons #' (e.g. XSS attacks) when using this function in Shiny or any other dynamic #' web applications. @@ -79,7 +80,8 @@ datatable = function( escape = TRUE, style = 'default', width = NULL, height = NULL, elementId = NULL, fillContainer = getOption('DT.fillContainer', NULL), autoHideNavigation = getOption('DT.autoHideNavigation', NULL), - selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL + selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL, + editable = FALSE ) { # yes, we all hate it @@ -198,6 +200,8 @@ datatable = function( params$caption = captionString(caption) + if (editable) params$editable = editable + if (!identical(class(callback), class(JS('')))) stop("The 'callback' argument only accept a value returned from JS()") if (length(options$pageLength) && length(options$lengthMenu) == 0) { diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index 2b607eed..8d8a9043 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -669,7 +669,7 @@ HTMLWidgets.widget({ if (typeof data.callback === 'function') data.callback(table); // double click to edit the cell - table.on('dblclick.dt', 'tbody td', function() { + if (data.editable) table.on('dblclick.dt', 'tbody td', function() { var $input = $(''); var $this = $(this), value = table.cell(this).data(), html = $this.html(); $input.val(value);