Skip to content

Commit

Permalink
Fix(Datatables JS): Refactor turbolinks cache fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisma committed Mar 23, 2019
1 parent a4f585d commit 7c552fb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/assets/javascripts/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ $(document).on('turbolinks:load', function() {
}
});

// https://stackoverflow.com/questions/41070556/how-can-i-prevent-duplicate-wrappers-on-a-jquery-datatable-when-navigating-back
// Turbolinks cache fix
// https://stackoverflow.com/questions/41070556
$(document).on('turbolinks:before-cache', function() {
var dataTable = $($.fn.dataTable.tables(true)).DataTable();
if (dataTable !== null) {
dataTable.clear();
dataTable.destroy();
return dataTable = null;
var tables = $.fn.dataTable.tables(true);
if (tables.length > 0) {
$(tables).DataTable().destroy();
}
});

0 comments on commit 7c552fb

Please sign in to comment.