我试过在DT :: datatable中搜索一个方法/选项来改变搜索框的默认宽度。答案可用于HTML / CSS等但我不知道如何在options = list(search = list(search =“”,width = 200px#或width =“200%”)中加入width = 200px或200%工作。
DT::datatable(
mtcars,options = list(dom="ft",search =list(search = 'Type here to search',
width= "200%")))
任何有关DT中dom元素的指导都将受到赞赏。谢谢。
我们可以通过两种方式设置RMarkdown,如here所示,然后我们可以使用不同的CSS选择器应用特定的样式,即id,类名甚至输入,如我们的情况。这是一个解决方案,包括直接在RMarkdown文件中的CSS。
---
title: "Untitled"
output:
html_document: default
pdf_document: default
---
<style>
h1.title{
color:red;
}
.dataTables_wrapper .dataTables_filter {
width: 100%;
float: none;
text-align: center;
//align the Search box to center. left and right also valid
}
input[type="search"] {
height: 28px;
width: 300px;
margin: 0;
padding: 0;
font-size: 10px;
border: 1px solid #CCCCCC;
}
</style>
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r cars}
library(DT)
#summary(cars)
DT::datatable(
mtcars,options = list(dom="ft",search =list(search = 'Type here to search')))
```
对我来说唯一有用的就是这个css。
$(document).ready(function(){
$('#datatable-buttons_filter').css({"position":"relative","left":"-100px"});
});