mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +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); | ||||
| } | ||||
| 
 | ||||
| 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.
 | ||||
|  | ||||
| @ -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({ | ||||
|  | ||||
| @ -76,12 +76,13 @@ class ColumnPicker extends Disposable { | ||||
|       void use(refreshTrigger); | ||||
| 
 | ||||
|       const columnsAsOptions: IOption<number|null>[] = use(canBeMapped) | ||||
|         .sort(labelsOrder) | ||||
|         .map((col) => ({ | ||||
|           value: col.getRowId(), | ||||
|           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.
 | ||||
|       // 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 {addToSort, updatePositions} from 'app/client/lib/sortUtil'; | ||||
| import {ViewSectionRec} from 'app/client/models/DocModel'; | ||||
| import {labelsOrder} from 'app/client/models/entities/ColumnRec'; | ||||
| import {ObjObservable} from 'app/client/models/modelUtil'; | ||||
| import {dropdownWithSearch} from 'app/client/ui/searchDropdown'; | ||||
| import {cssIcon, cssRow, cssSortFilterColumn} from 'app/client/ui/RightPanelStyles'; | ||||
| @ -215,7 +216,7 @@ export class SortConfig extends Disposable { | ||||
|       const currentSection = this._section; | ||||
|       const currentSortSpec = use(currentSection.activeSortSpec); | ||||
|       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; | ||||
|     return cssButtonRow( | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user