Client side table format serialization between sessions

Client side table format serialization between sessions

KoldoKoldo Posts: 2Questions: 1Answers: 0

I wanted to store locally between sessions (using localStorage) the table column order and sorting.
I've managed to do it with sorting by doing this:

var table;
var tableSort;

$(document).ready(function () {
                tableSort = JSON.parse(localStorage.getItem('TableSort'));
                table = $('#datatable').DataTable({
                  ...
                    "order": tableSort,
                  ...
                });
})

window.addEventListener('unload', function (event) {
                localStorage.setItem('TableSort', JSON.stringify(table.order()));
});

Is there a simple way to store in client column order so that even when the server creates the table following original order, in the initialization the table can be reordered to look as the user left it in previous session?

Thank you!
Koldo

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908

    Have you tried the stateSave option?

    Kevin

  • KoldoKoldo Posts: 2Questions: 1Answers: 0

    Thank you Kevin, good option.
    However it saves column sort, but not column locations and widths.

This discussion has been closed.