jquery - 如何解决数据表中闪亮的错位问题?
问题描述
我在尝试着
- 使数据表中的所有列具有相同的宽度
- 将数据表(标题及其内容)向左对齐
- 达到 mainPanel 宽度后启用水平滚动
但我的数据表会自动以主面板为中心,其标题和内容也未对齐。
例子:
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Test Example"),
mainPanel(
width = 10,
dataTableOutput("cars.table")
)
)
server <- function(input, output) {
output$cars.table <- renderDataTable({
t(cars[1:10, ]) %>%
datatable(class = "compact small",
options = list(columnDefs = list(list(width = "25px", targets = "_all")), scrollX = TRUE, autoWidth = TRUE,
paging = FALSE, ordering = FALSE, searching = FALSE))
})
}
shinyApp(ui = ui, server = server)
2019/05/03 更新:
我相信这个问题表明这个问题是由 引起的autoWidth = TRUE
,但是问题下没有解决方案,如果我们想调整列宽,我们也不能删除autoWidth = TRUE
。
解决方案
对于对齐,您可以使用className = dt-left
.
而且我猜参数 `fillContainer = T' 完成了滚动的工作。
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Test Example"),
mainPanel(
width = 10,
dataTableOutput("cars.table")
)
)
server <- function(input, output) {
output$cars.table <- renderDataTable({
t(cars[1:10, ]) %>%
datatable(class = "compact small", fillContainer = T,
options = list(columnDefs = list(list(className = 'dt-left', width = "25px", targets = "_all")), scrollX = TRUE,
paging = FALSE, ordering = FALSE, searching = FALSE))
})
}
shinyApp(ui = ui, server = server)
推荐阅读
- python-3.x - Django - 从查询集中“合并”或排序相似的对象
- c# - 当图表没有任何内容可显示时如何显示“无数据”
- javascript - 如何在 Angular 库中导入 js 文件?
- r - R:如何根据某些条件将值从多个数据帧传输到另一个数据帧?
- python - 使用 Plotly Graph 对象按中值对箱线图进行排序
- android - Expo Push Notifications 在生产中不起作用
- mongodb - 在 mongoDB 中按 _id 搜索是否更有效?
- javascript - 如何在 d3.format 中添加任何字符串作为数字的后缀?
- r - 从命令提示符执行 R 脚本时出错
- mongodb - 在 MongoDB 5.0.1 中创建时序集合会引发错误时序集合未启用