I followed some questions R datatable rotate header not aligning, but I am not sure how I can add parameter start, end
to the headerCallback
. I do have some columns no need to rotate 180 degree.
headerCallback <- c(
"function(thead, data, start, end, display){",
" var $ths = $(thead).find('th');",
" $ths.css({'vertical-align': 'bottom', 'white-space': 'nowrap'});",
" var betterCells = [];",
" $ths.each(function(){",
" var cell = $(this);",
" var newDiv = $('<div>', {height: 'auto', width: cell.height()});",
" var newInnerDiv = $('<div>', {text: cell.text()});",
" newDiv.css({margin: 'auto'});",
" newInnerDiv.css({",
" transform: 'rotate(180deg)',",
" 'writing-mode': 'tb-rl',",
" 'white-space': 'nowrap'",
" });",
" newDiv.append(newInnerDiv);",
" betterCells.push(newDiv);",
" });",
" $ths.each(function(i){",
" $(this).html(betterCells[i]);",
" });",
"}"
)
datatable(mtcars %>% mutate(name = row.names(mtcars),
id = row_number()) %>% select(id,name, everything()),
rownames = F,
class = list(stripe = FALSE),
options = list(
paging = F, autoWidth = F,
searching= FALSE,
scrollX = F,
# initComplete = JS("function(settings, json) {
# $(this.api().table().header()).css({
# 'font-size' : '12px'});}"),
headerCallback = JS(headerCallback))) %>%
formatStyle(columns = c(1:10), `font-size` = '12px')