设置DT :: Datatable的默认部分的样式

时间:2019-08-23 12:48:59

标签: r dt

我很想知道是否有一种样式(特别是更改颜色)DT数据表的默认部分,例如"Show Entries", "Search","Showing to of entries", "Previous" "Next"

library(DT)
datatable(iris)

1 个答案:

答案 0 :(得分:2)

一个问题中有很多问题。...

要更改“显示100个条目中的1至10个” ,请使用infoCallback选项。例如:

  infoCallback <- c(
    "function(settings, start, end, max, total, pre){",
    "  return 'Showing '+ start +' to '+ end +' of <b>'+ total +'</b> entries';",
    "}"
  )

这将以粗体显示条目总数。并将其放在选项中:options = list(infoCallback = JS(infoCallback))。参见https://datatables.net/reference/option/infoCallback

要更改“下一个”和“上一个”,请参阅this post

here和您有完整的描述。一个例子:

library(DT) 
datatable(
  mtcars, 
  options = 
    list(language = 
           list(paginate = 
                  list('next'="NEXT PAGE", 
                       previous="PREVIOUS PAGE"), 
                info = "These are entries _START_ to _END_ of _TOTAL_ total entries",
                lengthMenu = "Display _MENU_ entries",
                search = "Search box"
           )
    )
)

enter image description here

您可以使用一些HTML样式,例如颜色,例如:

library(DT) 
datatable(
  mtcars, 
  options = 
    list(language = 
           list(paginate = 
                  list('next'="NEXT PAGE", 
                       previous="PREVIOUS PAGE"), 
                info = "These are entries _START_ to _END_ of _TOTAL_ total entries",
                lengthMenu = "Display _MENU_ entries",
                search = "<span style='color:red'>Search box</span>"
           )
    )
)

enter image description here