buchungenUI <- function(id) { ns <- NS(id) tagList( reactableOutput(ns("buchungen_table")) ) } buchungenServer <- function(id) { moduleServer( id, function(input, output, session) { ns <- session$ns postings <- reactiveVal(read_buch_tabelle(conn)) output$buchungen_table <- renderReactable({ reactable( postings(), onClick = "expand", selection = "single", details = function(index) { entry_id <- postings()$entry_id[index] detail_rows <- postings()[postings()$entry_id == entry_id, ] div( style = "padding: 10px; background: #f4f4f4; border-left: 4px solid #3c8dbc; max-width: 800px; margin-left: auto", reactable( dplyr::select(detail_rows, konto, projektname, amount), fullWidth = TRUE, columns = list( konto = colDef(name = "Konto", minWidth = 150), projektname = colDef(name = "Projekt", minWidth = 150), amount = colDef(name = "Betrag", minWidth = 80) ) ) ) }, columns = list( id = colDef(name = "ID", minWidth = 80), valuta = colDef(name = "Wertstellung", minWidth = 80), konto = colDef(name = "Kontoname", minWidth = 200), entry_id = colDef(show = FALSE) ) ) }) # Modal zum editieren selected <- reactive(getReactableState("buchungen_table", "selected")) observeEvent(selected(),{ idwert <- postings()[selected(), "id"] selected_row <- read_posting(conn, idwert) %>% mutate(verzicht = ifelse(is.na(verzicht), F, verzicht)) showModal(modalDialog( title = "Buchung bearbeiten", size = "l", tags$style(HTML(".modal-dialog { max-width: 90% !important; width: 90% !important; }")), entryEditUI(ns("entry_edit")), footer = tagList( modalButton("Abbrechen"), actionButton(ns("speichern"), "Speichern") ) )) entryEditServer("entry_edit", entry_id = selected_row$entry_id, conn = conn) }, ignoreInit = TRUE) observeEvent(input$speichern, { browser() dbExecute(conn, "UPDATE postings SET account_id = ?, project_id = ?, amount = ?, valuta = ?, notiz = ?, rechnungsnummer = ?, betrag_muenzen = ?, verzicht = ? WHERE id = ?", params = list( input$account_id, input$project_id, input$amount, input$valuta, input$notiz, input$rechnungsnummer, input$betrag_muenzen, input$verzicht, selected_row$id ) ) removeModal() buchungen(read_buch_tabelle(conn)) # Tabelle neu laden }) } ) }