我想在一个DataTable在DT
页脚添加colsum添加页脚我https://github.com/rstudio/DT/issues/39
sketch <- htmltools::withTags(table(
tableHeader(cars),
tableFooter(cars)
))
datatable(cars,container = sketch, rownames = F,
options = list(
footerCallback = JS(
"function(tfoot, data, start, end, display) {",
"var api = this.api();",
"$(api.column(1).footer()).html(",
"api.column(1).data().reduce(function (a, b) {",
"return a + b;",
"})", # remove ; here
");",
"}")
)
)
我试图做到这一点对
做到了1列 - 所有列
- 所有NUM列(或所有除焦炭ID更容易)
编辑:解:)
dt_test <- structure(list(`pathologie principale` = c("Effet toxique des métaux",
"Autres résultats anormaux des examens chimiques du sang", "Néphrite tubulo-interstitielle chronique",
"Atteintes tubulo-interstitielles et tubulaires dues à des médicaments et des métaux lourds",
"Autres maladies pulmonaires obstructives chroniques", "Autres résultats anormaux de l'examen des urines"
), Fort = c(12L, 4L, 3L, 2L, 2L, 2L), Moyen = c(2L, 0L, 0L, 0L, 1L, 1L), Faible = c(4L, 0L, 0L, 0L, 4L, 0L)),
.Names = c("pathologie principale", "Fort", "Moyen", "Faible"), class = c("data.table", "data.frame"
), row.names = c(NA, -6L))
sketch <- htmltools::withTags(table(
tableHeader(dt_test),
tableFooter(sapply(dt_test, function(x) ifelse((is.numeric(x)) ,sum(x) ,"total"))
)))
datatable(dt_test,
container = sketch,
rownames = F
)
也许会更好地上下移动上述解决其自己的答案,这样就比较容易发现。 – demongolem