diff --git a/NEWS.md b/NEWS.md index d71e4f4b..2decec01 100644 --- a/NEWS.md +++ b/NEWS.md @@ -69,6 +69,8 @@ - Fixed a bug that triggers a DataTables warning dialog box in the browser (thanks, @zross, https://github.com/WHOequity/who-heat/issues/229 and https://github.com/rstudio/shiny/issues/561) +- Factors will a huge number of levels may slow down the rendering of the table significantly (thanks, @vnijs, #169). + # CHANGES IN DT VERSION 0.1 - Initial CRAN release. diff --git a/R/datatables.R b/R/datatables.R index 513656ce..384d8619 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -409,7 +409,7 @@ filterRow = function( if (t != 'disabled') tags$div( tags$select( multiple = 'multiple', style = 'width: 100%;', - lapply(d, function(x) tags$option(value = x, x)) + `data-options` = jsonlite::toJSON(as.character(d)) ), style = 'width: 100%; display: none;' ) diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index e2e96471..76c831b9 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -224,7 +224,11 @@ HTMLWidgets.widget({ if ($input.val() === '') filter[0].selectize.setValue([]); } }); - filter = $x.children('select').selectize({ + var $input2 = $x.children('select'); + filter = $input2.selectize({ + options: $input2.data('options').map(function(v, i) { + return ({text: v, value: v}); + }), plugins: ['remove_button'], hideSelected: true, onChange: function(value) {