Skip to content

Commit

Permalink
feat(theme-shared): remove prime table instance from table sort direc…
Browse files Browse the repository at this point in the history
…tive and add abp table instance

#2537
  • Loading branch information
mehmet-erim committed Jan 7, 2020
1 parent 9d448ef commit e92e164
Showing 1 changed file with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { Directive, Input, Optional, Self, SimpleChanges, OnChanges } from '@angular/core';
import { Table } from 'primeng/table';
import { SortOrder, SortPipe } from '@abp/ng.core';
import {
ChangeDetectorRef,
Directive,
Host,
Input,
OnChanges,
Optional,
Self,
SimpleChanges,
} from '@angular/core';
import clone from 'just-clone';
import { SortPipe, SortOrder } from '@abp/ng.core';
import snq from 'snq';
import { TableComponent } from '../components/table/table.component';

export interface TableSortOptions {
key: string;
Expand All @@ -15,13 +25,30 @@ export interface TableSortOptions {
export class TableSortDirective implements OnChanges {
@Input()
abpTableSort: TableSortOptions;

@Input()
value: any[] = [];
constructor(@Optional() @Self() private table: Table, private sortPipe: SortPipe) {}

get table(): TableComponent | any {
return (
this.abpTable || snq(() => this.cdRef['_view'].component) || snq(() => this.cdRef['context']) // 'context' for ivy
);
}

constructor(
@Host() @Optional() @Self() private abpTable: TableComponent,
private sortPipe: SortPipe,
private cdRef: ChangeDetectorRef,
) {}

ngOnChanges({ value, abpTableSort }: SimpleChanges) {
if (value || abpTableSort) {
if (this.table && (value || abpTableSort)) {
this.abpTableSort = this.abpTableSort || ({} as TableSortOptions);
this.table.value = this.sortPipe.transform(clone(this.value), this.abpTableSort.order, this.abpTableSort.key);
this.table.value = this.sortPipe.transform(
clone(this.value),
this.abpTableSort.order,
this.abpTableSort.key,
);
}
}
}

0 comments on commit e92e164

Please sign in to comment.