数据表也应用列格式来过滤 [英] DataTables apply column formatting to filter also
本文介绍了数据表也应用列格式来过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当使用 filter = 'top'
创建一个 datatable
并且还在列上使用格式化函数时,该格式化不会应用于该列的过滤器控件.有没有办法格式化过滤器控件?
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.
这篇关于数据表也应用列格式来过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文