Skip to content

Commit

Permalink
add editable parameter (#484)
Browse files Browse the repository at this point in the history
* add editable parameter

* revert indentation

* only add the editable param when it is TRUE (makes JSON serialization a little cleaner)
  • Loading branch information
carlganz authored and yihui committed Jan 19, 2018
1 parent 1163778 commit dab1dc6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion R/datatables.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<input type="text">');
var $this = $(this), value = table.cell(this).data(), html = $this.html();
$input.val(value);
Expand Down

0 comments on commit dab1dc6

Please sign in to comment.