@@ -119,7 +119,7 @@ class Datatable
119119
120120 // @todo chagen var to const/let
121121 protected $ columnSearchTemplate = <<<COLUMN_SEARCH_CONFIGURATION
122- var api = this.api();
122+ const api = this.api();
123123
124124 let columnsSearch = :searchTypes;
125125
@@ -266,8 +266,12 @@ class Datatable
266266
267267 // Save filters
268268 $('#:tagId .filters input, #:tagId .filters select').on('change', function () {
269- saveFilters();
269+ saveFilters(api );
270270 });
271+
272+ api.on('order', function() {
273+ saveFilters(api);
274+ })
271275 COLUMN_SEARCH_CONFIGURATION ;
272276
273277 protected $ genericSearchTemplate = <<<GENERIC_SEARCH_CONFIGURATION
@@ -351,27 +355,31 @@ class Datatable
351355
352356 dt.css(:tableCss);
353357
354- function saveFilters() {
358+ function saveFilters(api ) {
355359 let filters = {};
356360 $('#:tagId .filters input, #:tagId .filters select').each(function (index, item) {
357361 filters[index] = $(item).val();
358362 });
359-
360- localStorage.setItem('filters_:tagId', JSON.stringify(filters));
363+
364+ let order = api.order();
365+
366+ localStorage.setItem('filters_:tagId', JSON.stringify({filters, order}));
361367 }
362368
363369 function loadFilters(api) {
364- let filters = JSON.parse(localStorage.getItem('filters_:tagId'));
370+ let { filters, order} = JSON.parse(localStorage.getItem('filters_:tagId'));
365371 if (filters) {
366372 $('#:tagId .filters input, #:tagId .filters select').each(function (index, item) {
367373 $(item).val(filters[index]);
368374 api.columns(index).search(filters[index])
369375 });
370-
371- api.draw();
372376 }
377+ if (order) {
378+ api.order(order);
379+ }
380+ api.draw();
373381 }
374-
382+
375383 function validateDate(text) {
376384 text = text.replaceAll("/","-");
377385 var re = /^(\d{4}(-)\d{2}(-)\d{2}|\d{2}(-)\d{2}(-)\d{4})$/;
0 commit comments