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

RowGroup extension with rownames = TRUE #1109

Closed
3 tasks done
isthisthat opened this issue Jan 5, 2024 · 6 comments · Fixed by #1121
Closed
3 tasks done

RowGroup extension with rownames = TRUE #1109

isthisthat opened this issue Jan 5, 2024 · 6 comments · Fixed by #1121

Comments

@isthisthat
Copy link

isthisthat commented Jan 5, 2024

The RowGroup extension does not appear to work properly when rownames = TRUE. It repeats the row header for each row (even when the grouping column has the same value).
I'm aware of the support issues with DT, just filing this FYI. Thank you


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@yihui
Copy link
Member

yihui commented Jan 18, 2024

I'm not sure what you meant by "It repeats the row header for each row (even when the grouping column has the same value)". Here is my minimal reprex:

d = data.frame(
  Group = rep(xfun::n2w(1:3), length.out = 26),
  a = sample(26), b = letters, c = factor(rep(c('a', 'b'), 13)),
  d = Sys.Date() + 1:26, e = Sys.time() + 1000 * (1:26), row.names = LETTERS
)

DT::datatable(
  d, rownames = FALSE,
  options = list(rowGroup = list(dataSrc = 0), order = list(list(0, 'asc'))),
  extensions = 'RowGroup'
)

DT::datatable(
  d, rownames = TRUE,
  options = list(rowGroup = list(dataSrc = 1), order = list(list(1, 'asc'))),
  extensions = 'RowGroup'
)

rownames = FALSE

image

rownames = TRUE

image

@isthisthat
Copy link
Author

Sorry that was poor triaging on my part. There is no issue with rownames. The actual issue is with colReorder and rowGroup it seems. Here is a reproducible example:

renderDT({
  datatable(setDT(data.frame(A=c(1,2,3,4),B=c(5,6,7,8),G=c("a","a","b","b"))), rownames=FALSE,
          options = list(
                         colReorder = TRUE,
                         rowGroup = list(dataSrc = 2)
          ),
          extensions = c("ColReorder", "RowGroup")
  )
}, server=TRUE)

Initially the table is row-grouped by G. When you move column A (or any column) to the place where column G was, and sort by that column, the row-grouping changes to that column, for example:
image

@yihui
Copy link
Member

yihui commented Jan 22, 2024

d = data.frame(
  A = c(1, 2, 3, 4),
  B = c(5, 6, 7, 8),
  G = c("a", "a", "b", "b")
)

DT::datatable(
  d, rownames = FALSE,
  options = list(
    colReorder = TRUE,
    rowGroup = list(dataSrc = 2)
  ),
  extensions = c("ColReorder", "RowGroup")
)

Okay, I see the problem now. Technically it shouldn't be too difficult to fix. We need to reset the dataSrc attribute for the rowGroup extension in the column-reorder event:

I'm not sure if anyone wants to help. I don't have time to work on it at the moment, but can take another look in a couple of months if no one sends a PR.

@yihui
Copy link
Member

yihui commented Jan 25, 2024

Our great helper @mikmart has made it again! Now you can try the development version:

remotes::install_github('rstudio/DT')

@isthisthat
Copy link
Author

I can confirm it works! Thank you so much @mikmart , you're on a roll!!

@mikmart
Copy link
Contributor

mikmart commented Jan 25, 2024

Great, thanks for testing!

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

Successfully merging a pull request may close this issue.

3 participants