如何减少DT数据表中的行高 [英] How can I reduce row height in DT datatables

查看:60
本文介绍了如何减少DT数据表中的行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在呈现 DT 数据表(即降低高度)时获得更细的行

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)

推荐答案

如果添加 pageLength = 属性,您可以设置最初显示多少行。通过调整 lengthMenu = c(),您还可以控制下拉菜单中提供的尺寸,也可以使用打开或关闭搜索搜索= FALSE

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%')

通过使用帮助器功能,您可以像在网页上的传统CSS中一样设置样式。注意最后一个,行高应该调整行高。

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.

编辑:我将所有代码移到一起,以了解其工作原理。抱歉,我没有事先弄清楚。 %>%和DT的 devtools :: install_github( rstudio / DT)版本一样是必需的。

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.

这篇关于如何减少DT数据表中的行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆