diff --git a/R/fct_data_helpers.R b/R/fct_data_helpers.R index 6ff84fc..e7b6c1e 100644 --- a/R/fct_data_helpers.R +++ b/R/fct_data_helpers.R @@ -565,7 +565,11 @@ datatable_custom <- function( deferRender = TRUE, scrollResize = TRUE, scrollCollapse = TRUE, - colReorder = TRUE + colReorder = list( + enable = TRUE, + realtime = FALSE, + fixedColumnsLeft = 1 + ) ) fixed_opts <- list( initComplete = DT::JS( diff --git a/R/mod_common_forms.R b/R/mod_common_forms.R index 3012188..1f4a524 100644 --- a/R/mod_common_forms.R +++ b/R/mod_common_forms.R @@ -146,7 +146,7 @@ mod_common_forms_server <- function( targets = 0, render = checkbox_render )), - createdRow = checkbox_create_callback + rowCallback = row_callback )) }) @@ -226,7 +226,7 @@ mod_common_forms_server <- function( targets = 0, render = checkbox_render )), - createdRow = checkbox_create_callback + rowCallback = row_callback )) }) diff --git a/R/mod_study_forms.R b/R/mod_study_forms.R index 87be1a5..b2d8e48 100644 --- a/R/mod_study_forms.R +++ b/R/mod_study_forms.R @@ -268,7 +268,7 @@ mod_study_forms_server <- function( targets = 0, render = checkbox_render )), - createdRow = checkbox_create_callback + rowCallback = row_callback )) }) diff --git a/R/shiny.R b/R/shiny.R index 61ff0f6..764896b 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -6,35 +6,53 @@ shiny::registerInputHandler('CS.reviewInfo', function(val, ...) { }, TRUE) checkbox_callback <- DT::JS( + "table.on('column-reorder', function() {", + "table.rows().every(function() {", + "if (this.data()[0].reviewed == null) {", + "$(':checkbox', this.node()).", + "addClass('indeterminate').", + "prop('indeterminate', this.data()[0].updated == null).", + "prop('readOnly', this.data()[0].updated == false)", + "}", + "})", + "});", "table.on('click', 'input[type=\"checkbox\"]', function(){", - "var tblId = $(this).closest('.datatables').attr('id');", - "var cell = table.cell($(this).closest('td'));", - "var rowIdx = table.row($(this).closest('tr')).index();", - "var ids = cell.data().ids;", - "var review = $(this).is(':indeterminate') ? null : $(this).is(':checked');", - "cell.data().updated = review;", - "var info = {review: review, ids: ids, row: tblId + '_row_' + rowIdx};", - "Shiny.setInputValue(tblId + '_review_selection:CS.reviewInfo', info);", - "})" + "var tblId = $(this).closest('.datatables').attr('id');", + "var cell = table.cell($(this).closest('td'));", + "var rowIdx = table.row($(this).closest('tr')).index();", + "var ids = cell.data().ids;", + "var review = $(this).is(':indeterminate') ? null : $(this).is(':checked');", + "cell.data().updated = review;", + "var info = {review: review, ids: ids, row: tblId + '_row_' + rowIdx};", + "Shiny.setInputValue(tblId + '_review_selection:CS.reviewInfo', info);", + "});" ) checkbox_render <- DT::JS( "function(data, type, row, meta) {", - "var reviewed = data.reviewed;", - "var updated = data.updated;", - "return ``;", + "var reviewed = data.reviewed;", + "var updated = data.updated;", + "var cb_class = ''", + "if (reviewed == null) {", + "cb_class = updated == null ? '' : 'indeterminate'", + "} else {", + "cb_class = reviewed ? 'checked' : 'unchecked'", + "}", + "return ``;", "}" ) -checkbox_create_callback <- DT::JS( - "function(row, data, dataIndex) {", - "if (data[0].reviewed == null) {", - "let cb = row.cells[0].getElementsByTagName('input')[0]", - "cb.indeterminate = true;", - "}", +row_callback <- DT::JS( + "function(row, data) {", + "if (data[0].reviewed == null) {", + "$(':checkbox', row).", + "addClass('indeterminate').", + "prop('indeterminate', data[0].updated == null).", + "prop('readOnly', data[0].updated == false)", + "}", "}" ) diff --git a/inst/app/www/custom.js b/inst/app/www/custom.js index e4da91d..809b65b 100644 --- a/inst/app/www/custom.js +++ b/inst/app/www/custom.js @@ -18,7 +18,7 @@ $(document).ready(function() { $(':checkbox.indeterminate', table.rows().nodes()). prop('checked', params.checked). prop('indeterminate', false). - prop('readOnly', params.checked); + prop('readOnly', !params.checked); }); /* Define custom Shiny input binding for overall review checkbox.