rstudio / DT

R Interface to the jQuery Plug-in DataTables
https://rstudio.github.io/DT/
Other
587 stars 184 forks source link

Selection of multiple levels #1105

Open Watjoa opened 6 months ago

Watjoa commented 6 months ago

Hi people of DT

I have a question regarding the following issue:

In filtering a factor variable, we are currently able to click on the different levels by which all rows including one of our selections are displayed. For instance, I click on A and B, by which all rows having A or B are displayed.

But, what if I have multiple levels into these cells? For instance, a row includes both A and B (A, B) or both B and C (B, C). Does the DT team know how all unique values could be displayed in the filtering (A, B, C) but all rows including the selection are displayed as a consequence?

As an example: I have 3 rows, with following cells in the column 'category': A - A, B - B, C In the filtering, I am able to select A or B or C. When I click on A, the first 2 rows are displayed. When I add B to this selection, all rows are displayed.

Thanks in advance!

yihui commented 6 months ago

In this case, the column is no longer a factor, because a factor level can't have multiple values. For example, the string "A, B" is a level itself, instead of a level containing two levels.

I think you should make the column a character vector instead of factor. Then use regular expressions to search (e.g., A|B means matching either A or B). Here is an example: https://rstudio.github.io/DT/007-search.html

stla commented 6 months ago

Or use the SearchBuilder extension (only with server=FALSE in Shiny).