How can I reduce row height in DT datatables

别来无恙 提交于 2019-12-06 23:37:19

问题


I would like to be able to get 'slimmer' rows when rendering a DT datatable (ie decrease that height)

options(digits.secs=6)
library(data.table)
d = data.table(x = 1:10,time = as.POSIXct('2015-03-23 12:00:00.123'))
library(DT)
datatable(d)


回答1:


If you add the pageLength= attribute you can set how many rows to show initially. And by adjusting the lengthMenu= c() you can also control the sizes of offered in the drop down, You can also turn search on or off with searching =FALSE

   library(DT)
    datatable(d, options=list(
       pageLength = 3,
       lengthMenu = c(2, 12, 18),
       searching= FALSE))%>%

   formatStyle( 0, target= 'row',color = 'black', backgroundColor = 'yellow', fontWeight ='bold', lineHeight='70%')

And by using the helper functions you can set the style just as you would in traditional CSS on a webpage. Notice the last one, line-height should adjust the row height.

Edited: I moved all the code together for you to see how it works. Sorry I was not clearer up front. The %>%is necessary as is devtools::install_github("rstudio/DT") version of DT.



来源:https://stackoverflow.com/questions/42099418/how-can-i-reduce-row-height-in-dt-datatables

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