Skip to content
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

add editable parameter #484

Merged
merged 3 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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