Created
October 20, 2016 06:32
-
-
Save i-like-bikes/1ebb3123f26cc9f1f5e0812fb52e4c7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(DT) | |
require(shiny) | |
custom.CSS <- " | |
.dataTables_scrollBody thead{ | |
visibility:hidden; | |
} | |
.group{ | |
background-color:#333!important; | |
font-size:15px; | |
color:#fff!important; | |
opacity:0.7; | |
} | |
.hidden { | |
display: none; | |
} | |
" | |
ui <- shinyUI( bootstrapPage( | |
tags$span(icon("chevron-down"), style = "display: none;"), | |
DT::dataTableOutput('tbl'), | |
tags$head(tags$style(HTML(custom.CSS))) | |
)) | |
server = function(input, output) { | |
output$tbl = DT::renderDataTable( | |
iris %>% | |
datatable(, escape = FALSE, | |
options = list( | |
paging = FALSE, | |
searching = FALSE, | |
drawCallback = JS(" | |
function (settings) { | |
var api = this.api(); | |
var rows = api.rows( {page:'current'}).nodes(); | |
var last = null; | |
var colonne = api.row(0).data().length; | |
var totale = new Array(); | |
totale['Totale']= new Array(); | |
var groupid = -1; | |
var subtotale = new Array(); | |
api.column(5, {page:'current'}).data().each( function(group, i) { | |
if ( last !== group) { | |
groupid++; | |
$(rows).eq( i).before( | |
'<tr class=\"group\"><td><i class=\"fa fa-chevron-left\"></i></td><td colspan=\"8\">'+group+'</td></tr>' | |
); | |
last = group; | |
} | |
} | |
); | |
$('tbody').find('.group').each(function (group){ | |
var rowsCollapse = $(this).nextUntil('.group'); | |
$(rowsCollapse).toggleClass('hidden'); | |
}) | |
}") | |
), | |
callback = JS( | |
" | |
$('tbody').on('click', 'tr.group', function() { | |
var rowsCollapse = $(this).nextUntil('.group'); | |
var className = $(rowsCollapse).attr('class'); | |
$('tbody').find('.group').each(function (group){ | |
$(this).find('i.fa').addClass('fa-chevron-left'); | |
$(this).find('i.fa').removeClass('fa-chevron-down'); | |
var rowsCollapse1 = $(this).nextUntil('.group'); | |
$(rowsCollapse1).addClass('hidden'); | |
}); | |
if ( className.indexOf('hidden') >=0) { | |
$(this).find('i.fa').toggleClass('fa-chevron-left fa-chevron-down'); | |
$(rowsCollapse).toggleClass('hidden'); | |
}; | |
} | |
)" | |
) | |
) | |
) | |
} | |
shinyApp(ui,server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment