繁体   English   中英

R 数据表冻结前 N 列

[英]R data table freeze first N columns

我基本上在这里问和回答了相同的问题Fixing a column in Shiny DataTable while Scrolling Right doesn't work with the main key difference that my data table extension is Buttons and I can't change it because I need the users to be able to将数据导出到 cxv、excel 和 pdf。 不过,我需要阻止/冻结前两列。 有可能这样做吗? 这是我的数据表:

df <- datatable(df_data, 
                  rownames= F,
                  filter = 'top',
                  #lengthChange = T,
                  extensions = "Buttons",
                  caption = paste0("Min, Median, Max - Unfiltered data."),
                  options = list(scrollX = TRUE
                                 , autoWidth = TRUE
                                 , pageLength = 5
                                 #,  columnDefs = list(list(width = '200px', targets = c(0)  ))
                                 , initComplete = JS("function(settings, json) {","$(this.api().table().header()).css({'font-size': '10px'});","}")
                                 , dom = 'Blfrtip'
                                 ,searching = FALSE 
                                 , info = FALSE
                                 #, fixedColumns = list(leftColumns = 2)
                                 ,buttons = c('copy', 'csv', 'excel', 'pdf')
                  ))

到目前为止,我尝试添加 fixedColumns 参数但没有成功。 谢谢

我真的很高兴回答我自己的问题。 Initially, I read this useful resource: https://rstudio.github.io/DT/extensions.html However, they don't emphasize there that multiple extensions can be combined: I realized this by reading: https://github. com/rstudio/DT/issues/294这是我的表格的最终版本,现在确实允许我冻结前 N 列:

df <- datatable(df_data, 
                  rownames= F,
                  filter = 'top',
                  #lengthChange = T,
                  extensions = c("Buttons","FixedColumns"),
                  caption = paste0("Min, Median, Max - Unfiltered data."),
                  options = list(scrollX = TRUE
                                 , autoWidth = TRUE
                                 , pageLength = 5
                                 #,  columnDefs = list(list(width = '200px', targets = c(0)  ))
                                 , initComplete = JS("function(settings, json) {","$(this.api().table().header()).css({'font-size': '10px'});","}")
                                 , dom = 'Blfrtip'
                                 ,searching = FALSE 
                                 , info = FALSE
                                 , fixedColumns = list(leftColumns = 2)
                                 ,buttons = c('copy', 'csv', 'excel', 'pdf')
                  ))

我进行了测试,它在我的 Shiny 应用程序中运行良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM