rstudio / DT

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

[feature requested] Choice of type of filter by column ? (no automatic filter, no slider by default) #569

Open philibe opened 6 years ago

philibe commented 6 years ago

Hello,

My cases

I would like to choose the type of filter by column :)

TLDR :) I am aware that all I suggest take time. I would like only to not have automatic filter if it is too complicated or too long.

My workaround to not have automatic filter, for the column I want, is to cast the column to string, but I cannot do that for numeric.

Have a good day :)

My wishes :) except if it does exist but I didn't see it in rstudio/DT or datables.net

My wishes are to kept filter features but to disable automatic filter by type of variable, and to not have slider by default. Have I misread documentation or it doesn't exist ? :)

For example in my display definition, to kept search, filter:

  output$my_table <- DT::renderDataTable(
    DT::datatable( my_datas,
                   style = "bootstrap",   class = "compact", filter='top',
                   selection = c("single"),    
                   options = list(
                     deferRender = TRUE, 
                     bSortClasses = TRUE,iDisplayLength = 10,   width = "100%",
                     scrollX=TRUE,
                     autoWidth = TRUE,
                     lengthMenu  = list(c(5, 25, 50, 75, 100, -1), list('5', '25','50','75','100', 'All')),
                     search = list(
                       smart = TRUE,
                       regex = TRUE, 
                       caseInsensitive = TRUE
                     )
                   )
    )   
  )

but to have something like that for the filter

search = list
(
type = no_auto
)

where type would be auto, no_auto (without slider, like string filter)

and by column to have something like that for the filter

options = list(searchCols = list(
    list(type =string ),  # even if it's numeric
    list(type = auto),  # current DT shiny feature
    list(type = no_auto),
    list(type = range),  # current DT shiny feature for date and numeric
    list(type = no_range),   # for dates or numeric
    list(type = listbox_auto),   # automatic list box
    list(type = listbox= list (a,b,c,d)),   # custom list box
    list(type = listbox= my_list_from_distinct_datas()), # custom list box from distinct datas
  ))
philibe commented 5 years ago

My users don't like sliders because they don't search by range but by value, except some cases. So it's counter intuitive for them to type 2.3 ... 2.3, they would like 2.3 for example. Same thing for date.

Workaround for search number without interval for a unique number value. ( And for dates also).

              HTML(
                      "
                      <script>
                      function search_replace_interval(event ) {
                        //console.log(event.data.column_type);

                        if(event.keyCode == 13) {
                          before=$(this).val();
                          after=before;
                          // prefix by the $ if you are looking for a number without interval : 
                          //$34 will be replaced by 34...34 when type of column is integer (or date)
                          //$34 will be replaced by 33...35 when type of column is number (because the previous case is misplaced when number)
                          //$$34 will be replaced by 33...35 (to workaround the previous case when misplaced)
                          item=before.substring(before.lastIndexOf('$')+1);
                          if (before.substring(0,1)=='$') {
                            if (((before.substring(0,2)=='$$') || (event.data.column_type=='number')) 
                                  && (['number', 'integer'].indexOf(event.data.column_type) >= 0) )  {
                               after=eval(eval(item)-1)+'...'+eval(eval(item)+1); 
                            } else {
                               after=item+'...'+item; 
                            }
                            //console.log(after);
                          }
                          $(this).val(after)
                        }
                      }

                      $(document).on('shiny:inputchanged', function(event) {
                        $('.datatables thead [data-type~=\"number\"] input.form-control').on('keydown',{column_type:'number'},search_replace_interval);
                        $('.datatables thead [data-type~=\"integer\"] input.form-control').on('keydown',{column_type:'integer'},search_replace_interval);
                        $('.datatables thead [data-type~=\"date\"] input.form-control').on('keydown',{column_type:'date'},search_replace_interval);
                        $('.datatables thead [data-type~=\"time\"] input.form-control').on('keydown',{column_type:'time'},search_replace_interval);

                      });
                      </script>
                      "
                    )