DataTables将列格式应用于过滤 [英] DataTables apply column formatting to filter also

查看:82
本文介绍了DataTables将列格式应用于过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 filter ='top'创建数据表并在列上使用格式化功能时,格式未应用于该列的过滤器控件。有没有办法格式化过滤器控件?

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')

推荐答案

我认为Yanir在其中!如果您乘以100,然后

I think Yanir is halfway there! What if you multiplied by 100 and then

datatable(my_data, filter = 'top') %>%
  formatCurrency(columns = "wt_pctile", 
  currency = "%", 
  before = FALSE)

这可以防止排序时出现%s的两倍或三倍。

This prevents double or triple %s when sorting.

这篇关于DataTables将列格式应用于过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆