【发布时间】:2020-06-26 17:58:59
【问题描述】:
有没有办法使用DT::datatable() 将javascript 函数作为参数传递?我正在尝试使用colvis button's columnText 参数,但datatable() 总是转换字符串中的值。
我的表和这个很相似(我用一个容器作为头部,所以不能使用 colnames 参数)
library(DT)
sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, 'Species'),
th(colspan = 2, 'Sepal'),
th(colspan = 2, 'Petal')
),
tr(
lapply(rep(c('Length', 'Width'), 2), th)
)
)
))
# Work
datatable(iris,
extensions = c('Buttons'),
options = list(dom = c('Bfrtip'),
buttons = list(list(extend = 'colvis'))
),
container = sketch)
# Doesn't work
datatable(iris,
extensions = c('Buttons'),
options = list(dom = c('Bfrtip'),
buttons = list(list(extend = 'colvis',
columnText = function ( dt, idx, title ) { return (idx+1) }))
),
container = sketch)
【问题讨论】:
标签: r datatables dt