pre version 2
This commit is contained in:
@@ -145,8 +145,11 @@ class ColumnManager {
|
||||
let dragIndex = -1;
|
||||
let placeholder = null;
|
||||
|
||||
const pinnedKeys = ['select', 'azioni'];
|
||||
|
||||
thead.querySelectorAll('th').forEach(th => {
|
||||
if (th.querySelector('.col-resize-handle')) return;
|
||||
const colKey = th.dataset.column;
|
||||
if (!colKey || pinnedKeys.includes(colKey)) return;
|
||||
th.draggable = true;
|
||||
|
||||
th.addEventListener('dragstart', (e) => {
|
||||
@@ -228,8 +231,10 @@ class ColumnManager {
|
||||
const ths = this.table.querySelectorAll('thead th');
|
||||
this.columnOrder = [];
|
||||
const keysInOrder = [];
|
||||
const pinnedKeys = ['select', 'azioni'];
|
||||
ths.forEach((th, idx) => {
|
||||
const colKey = th.dataset.column || `col_${idx}`;
|
||||
if (pinnedKeys.includes(colKey)) return;
|
||||
keysInOrder.push(colKey);
|
||||
this.columnOrder.push(colKey);
|
||||
});
|
||||
@@ -240,6 +245,11 @@ class ColumnManager {
|
||||
|
||||
reorderColumns(keyOrder, persist = true) {
|
||||
if (!keyOrder || keyOrder.length === 0) return;
|
||||
|
||||
const pinnedKeys = ['select', 'azioni'];
|
||||
const dataOrder = keyOrder.filter(k => !pinnedKeys.includes(k));
|
||||
if (dataOrder.length === 0) return;
|
||||
|
||||
const thead = this.table.querySelector('thead');
|
||||
if (!thead) return;
|
||||
|
||||
@@ -257,7 +267,7 @@ class ColumnManager {
|
||||
const reordered = [];
|
||||
let lastRef = null;
|
||||
|
||||
keyOrder.forEach(key => {
|
||||
dataOrder.forEach(key => {
|
||||
const srcIdx = keyToThIndex[key];
|
||||
if (srcIdx !== undefined && cells[srcIdx]) {
|
||||
reordered.push(cells[srcIdx]);
|
||||
@@ -272,10 +282,26 @@ class ColumnManager {
|
||||
}
|
||||
lastRef = cell;
|
||||
});
|
||||
|
||||
const selectIdx = keyToThIndex['select'];
|
||||
if (selectIdx !== undefined) {
|
||||
const selectCell = cells[selectIdx];
|
||||
if (selectCell && row.firstChild !== selectCell) {
|
||||
row.insertBefore(selectCell, row.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
const azioniIdx = keyToThIndex['azioni'];
|
||||
if (azioniIdx !== undefined) {
|
||||
const azioniCell = cells[azioniIdx];
|
||||
if (azioniCell) {
|
||||
row.appendChild(azioniCell);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.columnOrder = [...keyOrder];
|
||||
this.columns.sort((a, b) => keyOrder.indexOf(a.key) - keyOrder.indexOf(b.key));
|
||||
this.columnOrder = [...dataOrder];
|
||||
this.columns.sort((a, b) => dataOrder.indexOf(a.key) - dataOrder.indexOf(b.key));
|
||||
this.columns.forEach((col, idx) => col.index = idx);
|
||||
|
||||
if (persist) this.persistState();
|
||||
|
||||
Reference in New Issue
Block a user