diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index 7e002884db..2fe908cf8e 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -27,7 +27,7 @@ import { getInitialData, localeInitializer } from './utils/initial-utils'; import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS } from './plugins/config/config.plugin'; import { ForDirective } from './directives/for.directive'; import { AbstractNgModelComponent } from './abstracts/ng-model.component'; -import { SortDirective } from './directives/sort.directive'; +import { TableSortDirective } from './directives/table-sort.directive'; @NgModule({ imports: [ @@ -47,7 +47,7 @@ import { SortDirective } from './directives/sort.directive'; EllipsisDirective, ForDirective, FormSubmitDirective, - SortDirective, + TableSortDirective, LocalizationPipe, SortPipe, PermissionDirective, @@ -70,7 +70,7 @@ import { SortDirective } from './directives/sort.directive'; FormSubmitDirective, LocalizationPipe, SortPipe, - SortDirective, + TableSortDirective, PermissionDirective, VisibilityDirective, InputEventDebounceDirective, diff --git a/npm/ng-packs/packages/core/src/lib/directives/index.ts b/npm/ng-packs/packages/core/src/lib/directives/index.ts index 7edf1b5f76..7b5927b3ad 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/index.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/index.ts @@ -3,4 +3,5 @@ export * from './ellipsis.directive'; export * from './for.directive'; export * from './form-submit.directive'; export * from './permission.directive'; +export * from './table-sort.directive'; export * from './visibility.directive'; diff --git a/npm/ng-packs/packages/core/src/lib/directives/sort.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/sort.directive.ts deleted file mode 100644 index c00892998d..0000000000 --- a/npm/ng-packs/packages/core/src/lib/directives/sort.directive.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Directive, ElementRef, Input, Optional, Self } from '@angular/core'; -import { Table } from 'primeng/table'; - -@Directive({ - selector: '[abpSort]', -}) -export class SortDirective { - constructor(private elementRef: ElementRef, @Optional() @Self() table: Table) { - console.warn(elementRef); - setInterval(() => console.warn(table.value), 1000); - } -} diff --git a/npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts new file mode 100644 index 0000000000..707f2ab6ef --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts @@ -0,0 +1,29 @@ +import { Directive, Input, Optional, Self, SimpleChanges, OnChanges } from '@angular/core'; +import { Table } from 'primeng/table'; +import { SortPipe, SortOrder } from '../pipes/sort.pipe'; + +export interface TableSortOptions { + key: string; + order: SortOrder; +} + +@Directive({ + selector: '[abpTableSort]', + providers: [SortPipe], +}) +export class TableSortDirective implements OnChanges { + @Input() + abpTableSort: TableSortOptions; + + @Input() + value: any[] = []; + + constructor(@Optional() @Self() private table: Table, private sortPipe: SortPipe) {} + + ngOnChanges({ value, abpTableSort }: SimpleChanges) { + if (value || abpTableSort) { + this.abpTableSort = this.abpTableSort || ({} as TableSortOptions); + this.table.value = this.sortPipe.transform(this.value, this.abpTableSort.order, this.abpTableSort.key); + } + } +} diff --git a/npm/ng-packs/packages/core/src/lib/pipes/sort.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/sort.pipe.ts index 262025345d..d31d4903c6 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/sort.pipe.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/sort.pipe.ts @@ -1,8 +1,9 @@ -import { Pipe, PipeTransform } from '@angular/core'; +import { Pipe, PipeTransform, Injectable } from '@angular/core'; import clone from 'just-clone'; export type SortOrder = 'asc' | 'desc'; +@Injectable() @Pipe({ name: 'abpSort', }) diff --git a/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html b/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html index acc0f578ef..822c5a9576 100644 --- a/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html +++ b/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html @@ -24,7 +24,8 @@ - + + diff --git a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.html b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.html index 36683ed839..db1397870d 100644 --- a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.html +++ b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.html @@ -29,9 +29,9 @@ /> {{ 'AbpIdentity::Actions' | abpLocalization }} {{ 'AbpIdentity::UserName' | abpLocalization }} - + + {{ 'AbpIdentity::EmailAddress' | abpLocalization }} @@ -73,11 +69,8 @@ {{ 'AbpIdentity::PhoneNumber' | abpLocalization }} - + + @@ -223,8 +216,5 @@ - + + diff --git a/npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html b/npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html index ef4a69daf4..dc043d1e9a 100644 --- a/npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html +++ b/npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html @@ -31,7 +31,8 @@ {{ 'AbpTenantManagement::Actions' | abpLocalization }} {{ 'AbpTenantManagement::TenantName' | abpLocalization }} - + + @@ -180,8 +177,5 @@ - + +