Last active
June 8, 2018 02:46
-
-
Save masatokawano/8c3cdfabaf4c29c6f0f69dd10fc5f95f to your computer and use it in GitHub Desktop.
Customize jquery datatables with coffeescript. csv export filename with date.
This file contains hidden or 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
ready = -> | |
table = $('#computers').dataTable({ | |
"dom": "<'row'<'col-md-6'l><'col-md-6'Bf>><'row'<'col-md-6'><'col-md-6'>><'row'<'col-md-12't>><'row'<'col-md-12'ip>>", | |
"buttons": [ | |
extend: 'csv', | |
text: '<strong>CSV</strong> file download', | |
filename: getfilename, | |
exportOptions: { | |
columns: [ 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11 ] | |
} | |
], | |
"lengthMenu": [[10, 25, 50, 100, -1],[10, 25, 50, 100, "All"]] | |
}); | |
$(document).on('turbolinks:load', ready); | |
getfilename = -> | |
date = new Date | |
localdate = new Date(date - (date.getTimezoneOffset() * 60 * 1000)) | |
'computers' + localdate.toISOString().replace /\..+$|[^\d]/g, '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment