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

Possible to add sorting and filtering to formattable? #27

Closed
sculptor3 opened this issue Sep 11, 2015 · 7 comments
Closed

Possible to add sorting and filtering to formattable? #27

sculptor3 opened this issue Sep 11, 2015 · 7 comments

Comments

@sculptor3
Copy link

Hi Renkun-Ken,

Thanks for this cool package! It really looks good and works well. I was wondering if it is possible to easily integrate dataTable features like sorting and filtering (as implemented in RStudio's DT library). I guess it's not that easy, but I am curious about you opinon.

Many thanks in advance.

Kind regards,
Jelle

@renkun-ken
Copy link
Owner

I guess it's better use DT instead. formattable is currently only designed for static content presentation with formatting applied to columns. It would be some major changes to make it more interactive, and probably would become the same with DT finally, and that's not the goal of this package though.

@sculptor3
Copy link
Author

Okay, I understand your opinion and I guess you are right.

@timelyportfolio
Copy link
Collaborator

@sculptor3, with v0.2 combining DT::datatable with formattable is easy with the function as.datatable.

Here is a simple example.

    # need v0.2, so uncomment below to install
    # devtools::install_github("renkun-ken/formattable@v0.2")

    library(formattable)

    as.datatable(
      formattable(
        mtcars,
        list(mpg = formatter(
          "span",
          style = x ~ style(
            display = "block",
            "border-radius" = "4px",
            "padding-right" = "4px",
            color = "white",
            "background-color" = rgb(x/max(x), 0, 0))
          )
        )
      )
    )

@sculptor3
Copy link
Author

Thanks! That's simply brilliant :-)

Best regards
Op 20 jun. 2016 15:40 schreef "timelyportfolio" notifications@github.com:

@sculptor3 https://github.com/sculptor3, with v0.2 combining
DT::datatable with formattable is easy with the function as.datatable.

Here is a simple example.

# need v0.2, so uncomment below to install
# devtools::install_github("renkun-ken/formattable@v0.2")

library(formattable)

as.datatable(
  formattable(
    mtcars,
    list(mpg = formatter(
      "span",
      style = x ~ style(
        display = "block",
        "border-radius" = "4px",
        "padding-right" = "4px",
        color = "white",
        "background-color" = rgb(x/max(x), 0, 0))
      )
    )
  )
)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#27 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AHII1ht8TJodNaaarwDEvAJnNPOLx3mcks5qNphhgaJpZM4F7nVU
.

@tarunparmar
Copy link

Saved me all the 8 hours I spent in making it work and realize it broke the DT row selection feature 😅
Thanks for the elegant fix.

@trizniak
Copy link

@sculptor3, with v0.2 combining DT::datatable with formattable is easy with the function as.datatable.

this is indeed an elegant and simple solution, but unfortunately datatable cannot incorporate/reproduce all elements/formatting in a formattable table
case in point : compare the original formattable with the datatable translation

df <- data.frame(
id = 1:10,
name = c("Bob", "Ashley", "James", "David", "Jenny", "Hans", "Leo", "John", "Emily", "Lee"),
age = c(28, 27, 30, 28, 29, 29, 27, 27, 31, 30),
grade = c("C", "A", "A", "C", "B", "B", "B", "A", "C", "C"),
test1_score = c(8.9, 9.5, 9.6, 8.9, 9.1, 9.3, 9.3, 9.9, 8.5, 8.6),
test2_score = c(9.1, 9.1, 9.2, 9.1, 8.9, 8.5, 9.2, 9.3, 9.1, 8.8),
final_score = c(9, 9.3, 9.4, 9, 9, 8.9, 9.25, 9.6, 8.8, 8.7),
registered = c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE),
stringsAsFactors = FALSE)

FTT <- formattable(df, list(
age = color_tile("white", "orange"),
grade = formatter("span", style=x ~ ifelse(x=="A", style(color="green", font.weight="bold"), NA)),
area(col = c(test1_score, test2_score)) ~ normalize_bar("pink", 0.2),
final_score = formatter("span", style=x ~ style(color=ifelse(rank(-x) <= 3, "green", "gray")),
x ~ sprintf("%.2f (rank: %02d)", x, rank(-x))),
registered = formatter("span", style=x ~ style(color=ifelse(x, "green", "red")),
x ~ icontext(ifelse(x, "ok", "remove"), ifelse(x, "Yes", "No")))
))

DT.FTT <- as.datatable(FTT)

FTT ; DT.FTT

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants