Home > Software engineering >  searchPanes with cascadePanes = TRUE - not working in R's datatable package
searchPanes with cascadePanes = TRUE - not working in R's datatable package

Time:10-25

I am using the R package DT to interface with datatables.

I want to initialise searchpanes with cascadePanes options set to true (https://datatables.net/extensions/searchpanes/examples/initialisation/cascadePanes.html).

But what ever I do - cascade doesn't work.

My R code below. Any help much appreciated.

library(data.table)
library(DT)
myData <- data.table(c1 = sample(letters[1:10], 100, replace=TRUE),
                 c2 = runif(100),
                 c3 = sample(letters[5:20], 100, replace=TRUE),
                 c4 = sample(letters[15:20], 100, replace=TRUE),
                 c5 = sample(letters[10:20], 100, replace=TRUE),
                 c6 = sample(letters[1:20], 100, replace=TRUE),
                 c7 = sample(letters[1:20], 100, replace=TRUE))

datatable(myData,
      rownames = FALSE,
      extensions = c("SearchPanes", "Select", "Buttons"),
      filter="top",
      options = list(
          searchHighlight = TRUE,
          search = list(regex = TRUE, caseInsensitive = TRUE),
          language =list(url='https://cdn.datatables.net/plug-ins/1.10.25/i18n/Danish.json',
                         searchPanes = list(collapse = "Udvælg Rækker")),
          buttons = list(
            list(extend ="searchPanes"),
            list(extend = "csv", text="Download tabellen")
          ),
          dom = "lfBtipr",
          pageLength = 25,
          columnDefs = list(
            list(searchPanes = list(list(cascadePanes = TRUE))
            ))

          )
        )

CodePudding user response:

If you move the cascadePanes = TRUE argument to the searchPanes option (remove it from the columnDefs option), it works:

searchPanes = list(collapse = "Udvælg Rækker", cascadePanes = TRUE)

But only if you insert P to the dom option, as indicated here, but then it breaks your collapse button. This is a known issue.

In the end, the solution is just to move the searchPanes config in the buttons definition:

buttons = list(
    list(extend = "searchPanes", config = list(cascadePanes = TRUE)),
    list(extend = "csv", text="Download tabellen")
    )
  •  Tags:  
  • r dt
  • Related