Skip to content

Instantly share code, notes, and snippets.

@masatokawano
Last active June 8, 2018 02:46
Show Gist options
  • Save masatokawano/8c3cdfabaf4c29c6f0f69dd10fc5f95f to your computer and use it in GitHub Desktop.
Save masatokawano/8c3cdfabaf4c29c6f0f69dd10fc5f95f to your computer and use it in GitHub Desktop.
Customize jquery datatables with coffeescript. csv export filename with date.
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