Skip to content

Commit 7df94b5

Browse files
authored
FIX: saving changes for single-column data (#15)
FIX: saving changes for single-column data
1 parent 775c33a commit 7df94b5

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

editbl/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: editbl
22
Type: Package
33
Version: 1.3.1
4-
Date: 2025-04-23
4+
Date: 2025-09-24
55
Title: 'DT' Extension for CRUD (Create, Read, Update, Delete) Applications in 'shiny'
66
Authors@R: c(person("Jasper", "Schelfhout", "", "jasper.schelfhout@openanalytics.eu",
77
role = c("aut", "cre")),

editbl/R/eDT.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ eDTServer <- function(
816816

817817
observeEvent(input$DT_cell_edit, {
818818
rv$edits <- input$DT_cell_edit
819-
rv$edits_react <- rv$edits_react + 1
819+
rv$edits_react <- rv$edits_react + 1
820820
})
821821

822822
observeEvent(rv$edits_react, {
@@ -1080,7 +1080,7 @@ eDTServer <- function(
10801080
}
10811081
})
10821082

1083-
observeEvent(input$confirmCommit, {
1083+
observeEvent(input$confirmCommit, {
10841084
req(!is.null(effectiveChanges()) && isTruthy(effectiveChanges()))
10851085
modified <- effectiveChanges()
10861086
cols <- as.character(dplyr::tbl_vars(data()))
@@ -1119,7 +1119,7 @@ eDTServer <- function(
11191119
if(!checkForeignTbls(inserted, foreignTbls())){
11201120
stop("You made invalid edits to a row.")
11211121
}
1122-
inserted <- inserted[,cols]
1122+
inserted <- inserted[,cols,drop=FALSE]
11231123

11241124
if(nrow(deleted)){
11251125
if(inherits(result, 'tbl_dbi') & in_place()){
@@ -1149,14 +1149,15 @@ eDTServer <- function(
11491149
DBI::dbRemoveTable(dbplyr::remote_con(result), temp_name)
11501150
}
11511151
}
1152+
11521153
if(nrow(edited)){
11531154
result <- e_rows_update(
11541155
x = result,
11551156
y = edited,
11561157
match = match,
11571158
by = keys(),
1158-
in_place = in_place())
1159-
}
1159+
in_place = in_place())
1160+
}
11601161

11611162
if(nrow(inserted)){
11621163
# Needed code should there be a switch to dbplyr::rows_insert
@@ -1187,7 +1188,7 @@ eDTServer <- function(
11871188
}
11881189

11891190
rv$committedData <- result
1190-
1191+
11911192
# Set modified and rendered to comitted version
11921193
# re-read data in case of in_place modification
11931194
# This is because certain backends might modify the row further with defaults etc.

editbl/inst/NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1.3.1
22
o Remove non-exported functions from documentation.
3+
o FIX: saving changes for single-column data
34
1.3.0
45
o FIX: castToTemplate removed first row of adapted data in case the template was empty.
56
o FEAT: Add a clone button for each row.

editbl/tests/testthat/test-eDT.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ test_that("Editing a single table column works", {
3636
app = eDTServer,
3737
args = list(data = data),
3838
expr = {
39-
session$setInputs(edit_row_1 = 1)
40-
session$setInputs(confirmCommit = 1)
39+
# Make a cell edit
40+
session$setInputs(DT_cell_edit = data.frame(
41+
row = 1,
42+
col = 1,
43+
value = 3
44+
))
45+
session$flushReact()
46+
47+
# Save changes
48+
session$setInputs(confirmCommit = 1)
49+
session$flushReact()
50+
51+
expect_true(rv$modifiedData[1,'one_column'] == 3)
52+
expect_true(rv$resultMessage == 'success.')
4153
})
42-
expect_true(TRUE)
4354
})
4455

4556
test_that("Deletion of a row works", {

0 commit comments

Comments
 (0)