Skip to content

Commit

Permalink
Add connected-tables vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 17, 2024
1 parent e71ce6a commit cf4169b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ set_auto_id <- function(data) {
return(data)
}

if (nrow(data) == 0) {
data$id <- numeric()
return(data)
}

data$id <- seq(1:nrow(data))
return(data)
}
Expand Down
1 change: 1 addition & 0 deletions R/tabulator_context.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ invoke_method <- function(widget, method_name, ...) {
}

#' Create a Tabulator Context Object
#'
#' A \code{tabulatorContext} object makes it possible to update your widget in a Shiny app.
#' @param output_id (character): A tabulator output id.
#' @param session shiny session object
Expand Down
51 changes: 51 additions & 0 deletions vignettes/articles/connectes-tables.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "Connecting tables"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup}
library(rtabulator)
```

With the setup option `movable_rows_connected_tables` you can move rows between two or more tables:

```{r}
sender_df <- head(iris, 3)
empty_df <- head(iris, 0)
tab_sender <- tabulator(
sender_df,
tabulator_options(
movable_rows = TRUE,
movable_rows_connected_tables = "#table-receiver",
movable_rows_receiver = "add",
movable_rows_sender = "delete",
placeholder = "All rows moved"
),
element_id = "table-sender"
)
tab_receiver <- tabulator(
empty_df,
tabulator_options(
placeholder = "Drag rows here"
),
element_id = "table-receiver"
)
tab_sender
tab_receiver
```

***

**Note**

In some browsers _moving rows functionality_ does not seem to work at the moment.

***

0 comments on commit cf4169b

Please sign in to comment.