Mémorise chez le client l'état tri de toutes les gt_tables

This commit is contained in:
Emmanuel Viennet 2023-12-07 19:42:57 +01:00
parent 0ddae54b9b
commit 04335e521a
2 changed files with 20 additions and 1 deletions

View File

@ -643,6 +643,7 @@
.assi-liste {
border: 1px solid gray;
border-radius: 12px;
margin-right: 12px;
padding: 12px;
}
#options-tableau label {
@ -657,5 +658,5 @@ table.liste_assi td.date {
width: 140px;
}
table.liste_assi td.actions {
width: 70px;
white-space: nowrap; /* boutons horizontalement */
}

View File

@ -156,6 +156,17 @@ function get_query_args() {
// Tables (gen_tables)
$(function () {
if ($("table.gt_table").length > 0) {
const url = new URL(document.URL);
const order_info_key = JSON.stringify(["table_order", url.pathname]);
let order_info;
const x = localStorage.getItem(order_info_key);
if (x) {
try {
order_info = JSON.parse(x);
} catch (error) {
console.error(error);
}
}
var table_options = {
paging: false,
searching: false,
@ -167,6 +178,13 @@ $(function () {
},
orderCellsTop: true, // cellules ligne 1 pour tri
aaSorting: [], // Prevent initial sorting
order: order_info,
drawCallback: function (settings) {
// permet de conserver l'ordre de tri des colonnes
let table = $("table.gt_table").DataTable();
let order_info = JSON.stringify(table.order());
localStorage.setItem(order_info_key, order_info);
},
};
$("table.gt_table").DataTable(table_options);
table_options["searching"] = true;