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

[FR] SearchBuilder works with Server-Side processing mode #963

Closed
3 tasks
AhmedKhaled945 opened this issue Feb 9, 2022 · 9 comments · Fixed by #1113
Closed
3 tasks

[FR] SearchBuilder works with Server-Side processing mode #963

AhmedKhaled945 opened this issue Feb 9, 2022 · 9 comments · Fixed by #1113
Assignees
Labels
enhancement extensions issues related to the extensions of the datatables library

Comments

@AhmedKhaled945
Copy link

Hello, so a really helpful extension added to this repo was SearchBuilder, and while using it, once i go to server processing mode (server = true), it doesn't work, and this is a must on my side because i am dealing with fairly large data,

So is there any solution for this?, whether to optimize the data flow on client side (server = false) or to make the extension work on server side processing?

Regards,


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/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.

@shrektan
Copy link
Collaborator

shrektan commented Feb 10, 2022

Unfortunately, you can't use the server-processing mode with SearchBuilder at the present.

The good news is, it's possible now. We will consider to implement this feature.

**Note for myself: ** we need to translate the following "searchBuilder" JSON message to R expression.

{"method":"update","data":{"tbl_state":{"time":1644504799036,"start":0,"length":10,"order":[],"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true},"columns":[{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}}],"childRows":[],"searchBuilder":{"criteria":[{"condition":"=","data":"Sepal.Width","type":"num","value":["3"]},{"condition":">","data":"Petal.Length","type":"num","value":["5"]}],"logic":"AND"},"page":0}}}	1644504799.0447066

quick example

library(shiny)
tbl = data.frame(
  COL_INT = 1:20,
  COL_DBL = as.double(101:120),
  COL_FAC = as.factor(LETTERS[1:20]),
  COL_STR = letters[1:20],
  COL_DATE = Sys.Date() + 1:20,
  COL_TIME = Sys.time() + (1:20) * 3600 * 24
)
ui = fluidPage(
  DT::DTOutput("tbl")
)
server = function(input, output, session) {
  output$tbl = DT::renderDT({
    DT::datatable(
      tbl, options = list(dom = "Qlfrtip"),
      extensions = c("SearchBuilder", "DateTime")
    )
  })
}
runApp(list(ui=ui, server=server))

@shrektan shrektan self-assigned this Feb 10, 2022
@shrektan shrektan added enhancement extensions issues related to the extensions of the datatables library labels Feb 10, 2022
@shrektan shrektan changed the title extensions not working with Server = TRUE [FR] SearchBuilder works with Server-Side processing mode Feb 10, 2022
@AhmedKhaled945
Copy link
Author

That would be really helpful, Thanks.

@shrektan
Copy link
Collaborator

shrektan commented Feb 12, 2022

The full condition possibilities

https://github.com/DataTables/SearchBuilder/blob/2a3ceb327baf397ff5522088facd1f9db8c8d2f9/src/criteria.ts#L867-L2003

But there's one issue need to be resolved first:

The conditions "=", ">=" and "<=" are encoded without properly "quote", thus on the Shiny side (I mean in the Ajax callback), the query content would be "", ">" and "<" only.

shiny::parseQueryString("searchBuilder[criteria][0][condition]=<=&searchBuilder[criteria][0][data]=COL_INT")
#> $`searchBuilder[criteria][0][condition]`
#> [1] "<"
#> 
#> $`searchBuilder[criteria][0][data]`
#> [1] "COL_INT"

Opening the developper tools, I find that the browser indicates the original data contains the "=" sign.

image

The "=" sign in the query string should be encoded as "%3D" but I'm not sure it's an issue of datatable itself or it's a DT issue.

@yihui any thoughts?

@shrektan
Copy link
Collaborator

shrektan commented Feb 12, 2022

@yihui , my investigation finds it could be a bug of DT, as the browser sends out correct encoded strings (in Chrome I can see the raw POST content).

DT/R/shiny.R

Lines 559 to 562 in cccd35e

# DataTables requests were sent via POST
params = URLdecode(rawToChar(req$rook.input$read()))
Encoding(params) = 'UTF-8'
params = shiny::parseQueryString(params, nested = TRUE)

Removing the URLdecode() will get the correct result, as shiny::parseQueryString() would perform URLdecode() internally. I'm going to file a fix later.

@isthisthat
Copy link

Hello, I see that this ticket is still open and it seems that the SearchBuilder DT extension does not work when server=TRUE (with latest R, shiny and DT). Are there plans to implement this soon? Thank you.

@yihui
Copy link
Member

yihui commented Apr 26, 2023

@isthisthat For now, due to limited resources, I'd say it's unlikely for us to implement it unless someone else implements it and sends a PR. Sorry!

@isthisthat
Copy link

Thanks for confirming!

@yihui
Copy link
Member

yihui commented Jan 20, 2024

@AhmedKhaled945 @isthisthat Great news: @mikmart has generously helped implement this feature! Now you can install the development version via

remotes::install_github('rstudio/DT')

and try it out.

Thanks everyone!

@isthisthat
Copy link

isthisthat commented Jan 22, 2024

It works!! Amazing work @mikmart !! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement extensions issues related to the extensions of the datatables library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants