<div class="dropdown-divider"></div>
<a class="dropdown-item label-with-material-icon"
- (click)="col.visible=!col.visible" *ngFor="let col of gridContext.columnSet.columns">
+ (click)="col.visible=!col.visible"
+ *ngFor="let col of gridContext.columnSet.sortForColPicker()">
<span *ngIf="col.visible" class="badge badge-success">✓</span>
<span *ngIf="!col.visible" class="badge badge-warning">✗</span>
<span class="ml-2">{{col.label}}</span>
return this.columns.filter(c => c.visible);
}
+ // Sorted visible columns followed by sorted non-visible columns.
+ // Note we don't sort this.columns directly as it would impact
+ // grid column display ordering.
+ sortForColPicker(): GridColumn[] {
+ const visible = this.columns.filter(c => c.visible);
+ const invisible = this.columns.filter(c => !c.visible);
+
+ visible.sort((a, b) => a.label < b.label ? -1 : 1);
+ invisible.sort((a, b) => a.label < b.label ? -1 : 1);
+
+ return visible.concat(invisible);
+ }
+
insertBefore(source: GridColumn, target: GridColumn) {
let targetIdx = -1;
let sourceIdx = -1;