Skip to content

Commit f8ae41f

Browse files
committed
UiPreferences: improve applying column preferences
When the column preferences are applied the column is updated directly, but some preferences can only be applied if the column is of a specific type (e.g. NumberColumn). If there are preferences set for these cases the preferences are lost. Normally this is ok, because the column can not handle these preferences, but it makes it impossible to e.g. use placeholder columns if the real column can only be created asynchronously. Therefore, introduce the interface ColumnPreferencesColumn which contains a getter and a setter for the whole preferences. If preferences are applied to such a column the whole TableColumnClientUiPreferenceDo is passed to the setter and later on these preferences are used as a fallback for preference values that can only be extracted from specific column types when the preferences are stored. 449721
1 parent 8344b94 commit f8ae41f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

eclipse-scout-core/src/prefs/TableUiPreferences.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,16 @@ export class TableUiPreferences implements ObjectWithType {
256256
sortOrder: column.sortIndex,
257257
sortAscending: column.sortAscending,
258258
groupingActive: column.grouped,
259-
aggregationFunctionId: column instanceof NumberColumn ? column.aggregationFunction : undefined,
260-
backgroundEffectId: column instanceof NumberColumn ? column.backgroundEffect : undefined
259+
aggregationFunctionId: column instanceof NumberColumn
260+
? column.aggregationFunction
261+
: this.isColumnPreferencesColumn(column)
262+
? column.getColumnPreferences()?.aggregationFunctionId
263+
: undefined,
264+
backgroundEffectId: column instanceof NumberColumn
265+
? column.backgroundEffect
266+
: this.isColumnPreferencesColumn(column)
267+
? column.getColumnPreferences()?.backgroundEffectId
268+
: undefined
261269
});
262270
});
263271
}
@@ -510,13 +518,21 @@ export class TableUiPreferences implements ObjectWithType {
510518
column.setAggregationFunction(columnPreferences.aggregationFunctionId as NumberColumnAggregationFunction);
511519
column.setBackgroundEffect(columnPreferences.backgroundEffectId as NumberColumnBackgroundEffect, false); // false = don't redraw
512520
}
521+
522+
if (this.isColumnPreferencesColumn(column)) {
523+
column.setColumnPreferences(columnPreferences);
524+
}
513525
}
514526

515527
protected _applyUserFilterStates(table: Table, userFilterStates: IUserFilterStateDo[], options?: ApplyTablePreferencesOptions) {
516528
if (options?.applyUserFilters) { // true when showing a bookmark
517529
table.applyUserFilterStates(userFilterStates);
518530
}
519531
}
532+
533+
isColumnPreferencesColumn<TValue>(column: Column<TValue> & Partial<Omit<ColumnPreferencesColumn<TValue>, keyof Column<TValue>>>): column is ColumnPreferencesColumn<TValue> {
534+
return objects.isFunction(column?.getColumnPreferences) && objects.isFunction(column.setColumnPreferences);
535+
}
520536
}
521537

522538
// --------------------------------------
@@ -571,3 +587,16 @@ UiPreferences.registerHandler(TableUiPreferences, {
571587
preferences.tablePreferences = tableUiPreferences._exportTablePreferences();
572588
}
573589
});
590+
591+
/**
592+
* Interface for {@link Column}s containing a getter and a setter for {@link TableColumnClientUiPreferenceDo}.
593+
* When preferences are applied to such a {@link Column} the whole {@link TableColumnClientUiPreferenceDo} is passed to the setter.
594+
* Later on these preferences are used as a fallback for preference values that can only be extracted from
595+
* specific column types (e.g. {@link NumberColumn#aggregationFunction} or {@link NumberColumn#backgroundEffect}) when the preferences are stored.
596+
*
597+
* With this one can e.g. implement placeholder columns that cache the preferences while the real columns are created asynchronously.
598+
*/
599+
export interface ColumnPreferencesColumn<TValue = any> extends Column<TValue> {
600+
getColumnPreferences: () => TableColumnClientUiPreferenceDo;
601+
setColumnPreferences: (columnPreferences: TableColumnClientUiPreferenceDo) => void;
602+
}

0 commit comments

Comments
 (0)