-
-
Save relish27/39099987149c445d16f19f088aeae407 to your computer and use it in GitHub Desktop.
Datatables.net code for XLS export, add appropriate bgcolor to cell
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
jQuery(document).ready(function($) { | |
// datatable display | |
if($('.output-table').length > 0) { | |
// default ordering | |
var output_order_col = 1; | |
var output_order_dir = "asc"; | |
var output_order = [[0,"asc"]]; | |
$( ".output-table" ).each(function() { | |
var output_filename = $(this).parents(".output").find(".output-filename").text(); | |
var output_title = $(this).parents(".output").find("h2.output-title").text(); | |
var output_intro = $(this).parents(".output").find(".output-intro-container").text(); | |
var output_legend_header = $(this).parents(".output").find(".legend.header").text(); | |
var output_legend_footer = $(this).parents(".output").find(".legend.footer").text(); | |
console.log("output_title: " + output_title); | |
//console.log("output_intro: " + output_intro); | |
//console.log("id: " + $(this).attr("id")); | |
var table_id = $(this).attr("id"); | |
console.log("table_id: " + table_id); | |
// custom ordering | |
switch(table_id) { | |
case "output-890": // State Rankings of CAH Reporting Rates for Inpatient Quality Measures, 2016 | |
case "output-898": // State Rankings of CAH Reporting Rates for Outpatient Quality Measures, 2016 | |
case "output-910": // State Rankings of HCAHPS Participation Rates for CAHs, 2016 | |
output_order = [[3,"desc"]]; | |
break; | |
case "output-854": // Inpatient and Outpatient Process of Care Results for Patients Discharged from Reporting CAHs in Alaska and All Other States, 2016 | |
case "output-905": // Inpatient and Outpatient Process of Care Results for Patients Discharged from Reporting CAHs, 2016 | |
output_order = [[0,"asc"],[1,"asc"]]; | |
break; | |
case "output-876": // Number of Completed HCAHPS Surveys and Response Rates for CAHs Nationally and in Hawaii, 2016 | |
output_order = [[1,"desc"]]; | |
break; | |
case "output-901": // Number of Completed HCAHPS Surveys and Response Rates for CAHs, 2016 | |
case "output-904": // Number of Completed HCAHPS Surveys and Response Rates for CAHs, 2016 | |
output_order = [[0,"asc"],[1,"asc"]]; | |
break; | |
default: | |
output_order = [[0,"asc"]]; | |
} | |
//console.log("output_order: " + output_order); | |
var output_table = $(this).DataTable({ | |
"paging": false, | |
"searching": false, | |
"bInfo": false, | |
"order": output_order, | |
dom: 'Bfrtip', | |
responsive: false, | |
"scrollX": true, | |
buttons: [ | |
{ | |
extend: 'excelHtml5', | |
dom: 'Bfrtip', | |
text: 'Download XLS', | |
title: output_filename, | |
messageTop: output_intro + '\n' + output_legend_header, | |
messageBottom: output_legend_footer, | |
customize: function( xlsx ) { | |
var sheet = xlsx.xl.worksheets['sheet1.xml']; | |
var row = 0; | |
$('row', sheet).each(function(x) { | |
if (x > 1) row++; | |
console.log(output_table.row(':eq('+row+')').data()) | |
if ($(output_table.cell(':eq('+row+')', 0).node()).hasClass('sig-w')) { | |
console.log('YES - sig-w'); | |
$('row:nth-child('+(x+1)+') c', sheet).attr('s', '10'); | |
} | |
else if ($(output_table.cell(':eq('+row+')', 0).node()).hasClass('sig-b')) { | |
console.log('YES - sig-b'); | |
$('row:nth-child('+x+') c', sheet).attr('s', '20'); | |
} | |
}); | |
} | |
}, | |
] | |
}); | |
// add download / print options | |
output_table.buttons().container().appendTo( $(this).parents(".output").find(".actions"), output_table.table().container() ); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment