diff --git a/packages/common/src/lib/entity/entity-table/entity-table.component.ts b/packages/common/src/lib/entity/entity-table/entity-table.component.ts index f2b9f454f3..ce326a5f60 100644 --- a/packages/common/src/lib/entity/entity-table/entity-table.component.ts +++ b/packages/common/src/lib/entity/entity-table/entity-table.component.ts @@ -76,6 +76,12 @@ export class EntityTableComponent implements OnInit, OnDestroy, OnChanges { @Input() scrollBehavior: EntityTableScrollBehavior = EntityTableScrollBehavior.Auto; + /** + * Whether nulls should be first when sorting + */ + @Input() + sortNullsFirst: boolean = false; + /** * Event emitted when an entity (row) is clicked */ @@ -196,7 +202,8 @@ export class EntityTableComponent implements OnInit, OnDestroy, OnChanges { if (direction === 'asc' || direction === 'desc') { this.store.view.sort({ valueAccessor: (entity: object) => this.getValue(entity, column), - direction + direction, + nullsFirst: this.sortNullsFirst }); } else { this.store.view.sort(undefined); diff --git a/packages/common/src/lib/entity/shared/entity.interfaces.ts b/packages/common/src/lib/entity/shared/entity.interfaces.ts index cfff5a0022..887d4b9e22 100644 --- a/packages/common/src/lib/entity/shared/entity.interfaces.ts +++ b/packages/common/src/lib/entity/shared/entity.interfaces.ts @@ -36,6 +36,12 @@ export type EntityFilterClause = (entity: E) => boolean; export interface EntitySortClause { valueAccessor: (entity: E) => string | number; direction: string; + + // If true, null and undefined values will be first + // If false, null and undefined values will be last + // If undefined, default to true and false when sorting in descending and + // ascending order, respectively + nullsFirst?: boolean; } export interface EntityJoinClause { diff --git a/packages/common/src/lib/entity/shared/view.ts b/packages/common/src/lib/entity/shared/view.ts index e371982b14..9956f01e3d 100644 --- a/packages/common/src/lib/entity/shared/view.ts +++ b/packages/common/src/lib/entity/shared/view.ts @@ -255,7 +255,7 @@ export class EntityView { clause.valueAccessor(v1), clause.valueAccessor(v2), clause.direction, - false + clause.nullsFirst ); }); }