DataTables apply column formatting to filter also

天涯浪子 提交于 2019-12-12 07:13:04

问题


When creating a datatable with filter = 'top' and also using a formatting function on a column, the formatting isn't applied to the filter control for that column. Is there a way to format the filter controls as well?

For example, if I have floating-point numbers formatted as a percentage, the slider in the filter still shows floating point numbers.

library(DT)

my_data <- mtcars
my_data$wt_pctile <- trunc(rank(my_data$wt)) / length(my_data$wt)

datatable(my_data,
          filter = 'top') %>%
  formatPercentage('wt_pctile')


回答1:


Not sure if there's a way to do it. A workaround can be multiplying by 100:

my_data$wt_pctile <- my_data$wt_pctile * 100

And than displaying as a string with the % sign:

datatable(my_data, filter = 'top') %>%
  formatString(suffix = "%",columns = "wt_pctile")


来源:https://stackoverflow.com/questions/46532497/datatables-apply-column-formatting-to-filter-also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!