Adding sort order for filters

This commit is contained in:
Jarosław Sadziński
2024-10-09 11:13:31 +02:00
parent 4cde2202b5
commit 1315cc366f
4 changed files with 15 additions and 8 deletions

View File

@@ -230,9 +230,14 @@ export function formatterForRec(
return func(args);
}
export function labelsOrder(a: ColumnRec, b: ColumnRec): number {
const left = a.label.peek().toLowerCase();
const right = b.label.peek().toLowerCase();
type ColumnInfo = {label: string}|{label: ko.Observable<string>};
function peekLabel(info: ColumnInfo): string {
return typeof info.label === 'string' ? info.label : info.label.peek();
}
export function labelsOrder(a: ColumnInfo, b: ColumnInfo): number {
const left = peekLabel(a).toLowerCase();
const right = peekLabel(b).toLowerCase();
// Order is as follows:
// - First columns with normal labels starting with a letter.

View File

@@ -521,7 +521,7 @@ export function createViewSectionRec(this: ViewSectionRec, docModel: DocModel):
const savedFiltersByColRef = new Map(this._savedFilters().all().map(f => [f.colRef(), f]));
const viewFieldsByColRef = new Map(this.viewFields().all().map(f => [f.origCol().getRowId(), f]));
return this.columns().map(column => {
return [...this.columns()].sort(labelsOrder).map(column => {
const savedFilter = savedFiltersByColRef.get(column.origColRef());
// Initialize with a saved filter, if one exists. Otherwise, use a blank filter.
const filter = modelUtil.customComputed({