How to add row borders and zebra stripes (row striping) to datatables DT in R?

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

I would like to know the proper way to add row borders styling and zebra stripes option to datatables created with the package DT in R.

Simple starter example:

library(DT) datatable(iris) 

Simple example with options:

datatable(head(iris, 20), options = list(   columnDefs = list(list(className = 'dt-center', targets = 4)),   pageLength = 5,   lengthMenu = c(5, 10, 15, 20) )) 

Not sure why I received a down vote? Please let me know if anything is unclear or how to improve this question.

回答1:

You can add the stripe and row-border class to the table container:

library(DT) library(htmltools) datatable(   head(iris, 20),   container = tags$table(     class="stripe row-border",     tags$thead(tags$tr(lapply(colnames(iris), tags$th)))   ) ) 

This will create the table container with both classes and the styling feature will be applied. You can add any other styling from the link you posted.



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