Fix Restore Column Order in Item Tree not always working

Closes #2521
This commit is contained in:
Adomas Venčkauskas 2022-04-11 13:55:23 +03:00
parent 4c445554a3
commit 237bd8f0ce
2 changed files with 21 additions and 4 deletions

View file

@ -372,6 +372,7 @@ class VirtualizedTable extends React.Component {
onColumnSort: PropTypes.func,
getColumnPrefs: PropTypes.func,
storeColumnPrefs: PropTypes.func,
getDefaultColumnOrder: PropTypes.func,
// Makes columns unmovable, unsortable, etc
staticColumns: PropTypes.bool,
// Used for initial column widths calculation
@ -1510,10 +1511,19 @@ var Columns = class {
restoreDefaultOrder = () => {
let prefs = this._getPrefs();
for (const column of this._columns) {
column.ordinal = this._virtualizedTable.props.columns.findIndex(
col => col.dataKey == column.dataKey);
prefs[column.dataKey].ordinal = column.ordinal;
if (this._virtualizedTable.props.getDefaultColumnOrder) {
let defaultOrder = this._virtualizedTable.props.getDefaultColumnOrder();
for (const column of this._columns) {
column.ordinal = defaultOrder[column.dataKey];
prefs[column.dataKey].ordinal = defaultOrder[column.dataKey];
}
}
else {
for (const column of this._columns) {
column.ordinal = this._virtualizedTable.props.columns.findIndex(
col => col.dataKey == column.dataKey);
prefs[column.dataKey].ordinal = column.ordinal;
}
}
this._columns.sort((a, b) => a.ordinal - b.ordinal);
this._storePrefs(prefs);

View file

@ -955,6 +955,7 @@ var ItemTree = class ItemTree extends LibraryTree {
onColumnSort: this.collectionTreeRow.isFeed() ? null : this._handleColumnSort,
getColumnPrefs: this._getColumnPrefs,
storeColumnPrefs: this._storeColumnPrefs,
getDefaultColumnOrder: this._getDefaultColumnOrder,
containerWidth: this.domEl.clientWidth,
multiSelect: true,
@ -3107,6 +3108,12 @@ var ItemTree = class ItemTree extends LibraryTree {
this._writeColumnPrefsToFile();
}
_getDefaultColumnOrder = () => {
let columnOrder = {};
this.getColumns().forEach((column, index) => columnOrder[column.dataKey] = index);
return columnOrder;
}
_loadColumnPrefsFromFile = async () => {
if (!this.props.persistColumns) return;
try {