mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
Adding sort order for filters
This commit is contained in:
parent
4cde2202b5
commit
1315cc366f
@ -230,9 +230,14 @@ export function formatterForRec(
|
|||||||
return func(args);
|
return func(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function labelsOrder(a: ColumnRec, b: ColumnRec): number {
|
type ColumnInfo = {label: string}|{label: ko.Observable<string>};
|
||||||
const left = a.label.peek().toLowerCase();
|
function peekLabel(info: ColumnInfo): string {
|
||||||
const right = b.label.peek().toLowerCase();
|
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:
|
// Order is as follows:
|
||||||
// - First columns with normal labels starting with a letter.
|
// - First columns with normal labels starting with a letter.
|
||||||
|
@ -521,7 +521,7 @@ export function createViewSectionRec(this: ViewSectionRec, docModel: DocModel):
|
|||||||
const savedFiltersByColRef = new Map(this._savedFilters().all().map(f => [f.colRef(), f]));
|
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]));
|
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());
|
const savedFilter = savedFiltersByColRef.get(column.origColRef());
|
||||||
// Initialize with a saved filter, if one exists. Otherwise, use a blank filter.
|
// Initialize with a saved filter, if one exists. Otherwise, use a blank filter.
|
||||||
const filter = modelUtil.customComputed({
|
const filter = modelUtil.customComputed({
|
||||||
|
@ -76,12 +76,13 @@ class ColumnPicker extends Disposable {
|
|||||||
void use(refreshTrigger);
|
void use(refreshTrigger);
|
||||||
|
|
||||||
const columnsAsOptions: IOption<number|null>[] = use(canBeMapped)
|
const columnsAsOptions: IOption<number|null>[] = use(canBeMapped)
|
||||||
.sort(labelsOrder)
|
|
||||||
.map((col) => ({
|
.map((col) => ({
|
||||||
value: col.getRowId(),
|
value: col.getRowId(),
|
||||||
label: col.label.peek() || '',
|
label: col.label.peek() || '',
|
||||||
icon: 'FieldColumn',
|
icon: 'FieldColumn' as const,
|
||||||
}));
|
}))
|
||||||
|
.sort(labelsOrder);
|
||||||
|
|
||||||
|
|
||||||
// For optional mappings, add 'Blank' option but only if the value is set.
|
// For optional mappings, add 'Blank' option but only if the value is set.
|
||||||
// This option will allow to clear the selection.
|
// This option will allow to clear the selection.
|
||||||
|
@ -4,6 +4,7 @@ import * as kf from 'app/client/lib/koForm';
|
|||||||
import {makeT} from 'app/client/lib/localization';
|
import {makeT} from 'app/client/lib/localization';
|
||||||
import {addToSort, updatePositions} from 'app/client/lib/sortUtil';
|
import {addToSort, updatePositions} from 'app/client/lib/sortUtil';
|
||||||
import {ViewSectionRec} from 'app/client/models/DocModel';
|
import {ViewSectionRec} from 'app/client/models/DocModel';
|
||||||
|
import {labelsOrder} from 'app/client/models/entities/ColumnRec';
|
||||||
import {ObjObservable} from 'app/client/models/modelUtil';
|
import {ObjObservable} from 'app/client/models/modelUtil';
|
||||||
import {dropdownWithSearch} from 'app/client/ui/searchDropdown';
|
import {dropdownWithSearch} from 'app/client/ui/searchDropdown';
|
||||||
import {cssIcon, cssRow, cssSortFilterColumn} from 'app/client/ui/RightPanelStyles';
|
import {cssIcon, cssRow, cssSortFilterColumn} from 'app/client/ui/RightPanelStyles';
|
||||||
@ -215,7 +216,7 @@ export class SortConfig extends Disposable {
|
|||||||
const currentSection = this._section;
|
const currentSection = this._section;
|
||||||
const currentSortSpec = use(currentSection.activeSortSpec);
|
const currentSortSpec = use(currentSection.activeSortSpec);
|
||||||
const specRowIds = new Set(currentSortSpec.map(_sortRef => Sort.getColRef(_sortRef)));
|
const specRowIds = new Set(currentSortSpec.map(_sortRef => Sort.getColRef(_sortRef)));
|
||||||
return use(columns).filter(_col => !specRowIds.has(_col.value));
|
return use(columns).filter(_col => !specRowIds.has(_col.value)).sort(labelsOrder);
|
||||||
});
|
});
|
||||||
const {menuOptions} = this._options;
|
const {menuOptions} = this._options;
|
||||||
return cssButtonRow(
|
return cssButtonRow(
|
||||||
|
Loading…
Reference in New Issue
Block a user