![](/img/trans.png)
[英]Select only filtered rows using select all button that comes with select extension in shiny's DT package
[英]Shiny DT, custom button to select filtered rows
我想在下面的最小可重現示例中包含自定義按鈕作為data.table
的擴展。 這個例子基本上取自這個問題。
由於我的應用程序中有幾個data.tables
,我嘗試使用 function var table = $(this.api().table().node()).DataTable();
來概括按鈕action
定義的JS
代碼中的節點var table = $(this.api().table().node()).DataTable();
,這是行不通的。 如果我插入var table = $('#DataTables_Table_0').DataTable();
它工作正常,但不再通用。
非常感謝任何幫助!
library(shiny)
library(DT)
ui <- fluidPage(
titlePanel("Select only filtered rows using selectall button"),
br(),
br(),
DT::dataTableOutput("tableTest")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$tableTest <- DT::renderDataTable({
datatable(mtcars,
escape = F,
rownames = F,
filter = 'top',
class = "compact hover row-border",
extensions = c('Scroller', 'Select', 'Buttons'),
options = list(
select = list(style = "multi", items = "row"),
columnDefs = list(list(className = 'dt-center', targets = "_all")),
language = list(info = 'Showing _START_ to _END_ of _TOTAL_ variables'),
deferRender = TRUE,
scrollY = 500,
scroller = TRUE,
dom = "Blfrtip",
buttons =
list(
list(extend='selectAll',
className='selectAll',
text="select all rows",
action = DT::JS(
"function () {
var table = $(this.api().table().node()).DataTable();
table.rows({ search: 'applied'}).deselect();
table.rows({ search: 'applied'}).select();
}")
),
list(extend='selectNone',
text="DeselectAll",
action = DT::JS(
"function () {
var table = $(this.api().table().node()).DataTable();
table.rows({ search: 'applied'}).select();
table.rows({ search: 'applied'}).deselect();
}")
))
),
selection = "none"
) }, server = F
)
}
# Run the application
shinyApp(ui = ui, server = server)
我沒有嘗試過,但我認為你可以這樣做:
action = JS(
"function(e, table, node, config) {",
" table.rows({ search: 'applied'}).deselect();",
" table.rows({ search: 'applied'}).select();",
"}"
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.