DataTable TableTools扩展实现 [英] DataTable TableTools Extension Implementation in Shiny

查看:195
本文介绍了DataTable TableTools扩展实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dataTabe为了导出csv格式的记录,我试图实现tableTools。但是,当过滤数据超过1页的记录时,如在此处提供的示例中,导出按钮不会在第2页及以后的页面上提取记录,并且仅导出第1页。

I've got a dataTabe for which I'm trying to implement tableTools in order to export the records in csv format. However, when the filtered data is more than 1 page worth of records, as in the example provided here, the export button doesn't pick up the records on the 2nd page and onwards and it only exports the 1st page.

从我的研究来看,似乎 oSelectorOps:{page:'all'} 选项应该做的伎俩。但是我无法让它工作。如果您运行下面的代码并点击导出按钮,它将导致只有100行(即第一页)的csv文件,而不是整个表。请指出我的语法是否错误,或者是否有更好的替代方法来实现。

From my research, it appears that oSelectorOps:{ page: 'all' } option should do the trick. However I couldn't get it to work. If you run the code below and hit the export button, it will result in a csv file with only 100 rows (i.e. the first page) and not the entire table. Please advise if my syntax is incorrect or if there's a better alternative to attain this.

请注意,我不想使用 downloadHandler ,因为我希望能够使用DataTable过滤器字段在表格底部进行过滤时导出数据。

Please note that I don't want to use the downloadHandler because I would like to be able to export the data when filtered using the DataTable filter fields, at the bottom of the table.

请点击此处 here 帮助解决类似问题。

Please click here and here to help with similar questions.

这是我的可重现的例子:

Here's my reproducible example:

#Load required packages
require(shiny)

#Create a dataframe
df <- data.frame(random=1:160)

server <- function(input,output,session){

    #Display df using DataTable and apply desired options
    output$display <- renderDataTable({df}, 
           option=list(pageLength=100,
                       "dom" = 'T<"clear">lfrtip',
                       "tableTools" = list(
                        "sSwfPath" = "//cdn.datatables.net/tabletools/2.2.3/swf/copy_csv_xls_pdf.swf",
                        "aButtons" = list(list("sExtends" = "csv","oSelectorOpts"=list("page"="all"),"sButtonText" = "Export","aButtons" ="csv")))         
       )

   )
}

ui <- shinyUI(fluidPage(

    #Add a title
    h1('Testing TableTools'),

    #Add required JS libraries
    tagList(
        singleton(tags$head(tags$script(src='//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js',type='text/javascript'))),
        singleton(tags$head(tags$script(src='//cdn.datatables.net/tabletools/2.2.3/js/dataTables.tableTools.min.js',type='text/javascript'))),
        singleton(tags$head(tags$link(href='//cdn.datatables.net/tabletools/2.2.3/css/dataTables.tableTools.css',rel='stylesheet',type='text/css')))
            ),


        mainPanel(
           #Display results
           dataTableOutput('display')
                 )      


))

shinyApp(ui = ui, server = server)


推荐答案

p>

Try this out:

{
sExtends: "csv",
"oSelectorOpts": {
    page: 'all',
    filter:'applied'
    },
"mColumns": "visible"
},

这篇关于DataTable TableTools扩展实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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