Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to create nested reactable with JS? #400

Open
krystian8207 opened this issue Dec 20, 2024 · 0 comments
Open

Is there a way to create nested reactable with JS? #400

krystian8207 opened this issue Dec 20, 2024 · 0 comments

Comments

@krystian8207
Copy link

Hi! Thank you for your hard work on this amazing and highly customizable package.

I'm currently working on a large table having multiple columns that store nested tibbles.
I want to display the nested columns as expandable cells.
For that goal I'm defining details argument of colDef as an R function that returns reactable object.

Here's the minimal example:

library(reactable)
mt_nested <- mtcars |> tidyr::nest(more = mpg:cyl, .by = am)
str(mt_nested)
#> tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ am  : num [1:2] 1 0
#>  $ more:List of 2
#>   ..$ : tibble [13 × 2] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ mpg: num [1:13] 21 21 22.8 32.4 30.4 33.9 27.3 26 30.4 15.8 ...
#>   .. ..$ cyl: num [1:13] 6 6 4 4 4 4 4 4 4 8 ...
#>   ..$ : tibble [19 × 2] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ mpg: num [1:19] 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 ...
#>   .. ..$ cyl: num [1:19] 6 8 6 8 4 4 6 6 8 8 ...

reactable(
  mt_nested, 
  columns = list(
    more = colDef(
      cell = JS(
        "function(cellInfo) {
          return cellInfo.value.cyl.length + ' entries';
        }"
      ),
      details = function(index) {
        htmltools::div(
          style = "padding: 1rem", 
          reactable(mt_nested$more[[index]])
        )
      }
    )
  )
)

out

The issue is defining details as an R function makes rendering the table a bit slow.
I wonder if there's a way to create nested reactable with defining details argument as a JS function?

Something like:

details = JS(
  "function(rowInfo, state) {
    renderReactable(rowInfo.values.more)
  }"
)

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant