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

Allow string options$columnDefs$targets #948

Merged
merged 12 commits into from
Jan 20, 2022
Merged

Allow string options$columnDefs$targets #948

merged 12 commits into from
Jan 20, 2022

Conversation

shrektan
Copy link
Collaborator

@shrektan shrektan commented Dec 4, 2021

Due to implentation of DT, options$columnDefs$targets doesn't support string values (See #512).

It's inconvinient as using column-names is always easier. In addition, it confuses the user in the first place, as it is inconsistent with DataTables' documentation.

This PR addresses this issue by converting the string valued targets into column index values of the data, internally.

CODE

x <- rnorm(10)
rk <- rank(x)
prefix <- sample(LETTERS[1:3], replace = TRUE, 10)
x_txt <- sprintf("%s%0.2f%%", prefix, x * 100)
tbl <- data.frame(V1 = x, V2 = x_txt, V3 = x, RK = rk)
DT::datatable(tbl, options = list(
  scrollY=FALSE, 
  columnDefs = list(
    list(visible = FALSE, targets = list("V3", 2))
  )
))

Before the PR ("V3" is visible but it should not)

image

After the PR ( "V3" is now invisible, as expected)

image

Copy link
Member

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great! Feel free to merge the PR by yourself whenever you are ready (I only had a quick look). Thanks!

Merge remote-tracking branch 'origin/main' into allow-string-targets

# Conflicts:
#	NEWS.md
@shrektan shrektan merged commit bae7043 into main Jan 20, 2022
@shrektan shrektan deleted the allow-string-targets branch January 20, 2022 17:30
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

Successfully merging this pull request may close these issues.

2 participants