Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: data table column filter templating #599

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,42 +155,44 @@
[attr.aria-label]="('OCX_DATA_TABLE.TOGGLE_BUTTON.ARIA_LABEL' | translate: { column: (column.nameKey | translate), direction: (sortDirectionToTitle(columnNextSortDirection(column.id)) | translate)})"
></button>
<ng-container *ngIf="currentEqualFilterOptions$ | async as equalFilterOptions">
<p-multiSelect
class="filterMultiSelect"
*ngIf="column.filterable && (!column.filterType || column.filterType === FilterType.EQUAL)"
[options]="equalFilterOptions.column?.id === column.id ? equalFilterOptions.options : []"
[ngModel]="(currentEqualSelectedFilters$ | async) || []"
[showToggleAll]="true"
emptyFilterMessage="{{ 'OCX_DATA_TABLE.EMPTY_FILTER_MESSAGE' | translate }}"
[displaySelectedLabel]="false"
[resetFilterOnHide]="true"
(onChange)="onMultiselectFilterChange(column, $event)"
placeholder="Icon"
appendTo="body"
(onFocus)="onFilterChosen(column)"
[title]="'OCX_DATA_TABLE.FILTER_TITLE' | translate"
[ariaLabel]="'OCX_DATA_TABLE.COLUMN_FILTER_ARIA_LABEL' | translate"
[ariaFilterLabel]="('OCX_DATA_TABLE.FILTER_ARIA_LABEL' | translate: { column: column.nameKey | translate})"
>
<ng-template pTemplate="selectedItems" let-value>
<div
class="pi"
[class.pi-filter]="!((filterAmounts$ | async) || {})[column.id]"
[class.pi-filter-fill]="((filterAmounts$ | async) || {})[column.id] > 0"
></div>
</ng-template>
<ng-template pTemplate="item" let-value>
<ng-container
*ngIf="columnTemplates[column.id] as template"
[ngTemplateOutlet]="template"
[ngTemplateOutletContext]="{
<ng-container *ngIf="columnFilterTemplates$ | async as columnFilterTemplates">
<p-multiSelect
class="filterMultiSelect"
*ngIf="column.filterable && (!column.filterType || column.filterType === FilterType.EQUAL)"
[options]="equalFilterOptions.column?.id === column.id ? equalFilterOptions.options : []"
[ngModel]="(currentEqualSelectedFilters$ | async) || []"
[showToggleAll]="true"
emptyFilterMessage="{{ 'OCX_DATA_TABLE.EMPTY_FILTER_MESSAGE' | translate }}"
[displaySelectedLabel]="false"
[resetFilterOnHide]="true"
(onChange)="onMultiselectFilterChange(column, $event)"
placeholder="Icon"
appendTo="body"
(onFocus)="onFilterChosen(column)"
[title]="'OCX_DATA_TABLE.FILTER_TITLE' | translate"
[ariaLabel]="'OCX_DATA_TABLE.COLUMN_FILTER_ARIA_LABEL' | translate"
[ariaFilterLabel]="('OCX_DATA_TABLE.FILTER_ARIA_LABEL' | translate: { column: column.nameKey | translate})"
>
<ng-template pTemplate="selectedItems" let-value>
<div
class="pi"
[class.pi-filter]="!((filterAmounts$ | async) || {})[column.id]"
[class.pi-filter-fill]="((filterAmounts$ | async) || {})[column.id] > 0"
></div>
</ng-template>
<ng-template pTemplate="item" let-value>
<ng-container
*ngIf="columnFilterTemplates[column.id] as template"
[ngTemplateOutlet]="template"
[ngTemplateOutletContext]="{
rowObject: getRowObjectFromMultiselectItem(value, column),
column: column
}"
>
</ng-container>
</ng-template>
</p-multiSelect>
>
</ng-container>
</ng-template>
</p-multiSelect>
</ng-container>
</ng-container>
<p-multiSelect
class="filterMultiSelect"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
this?._sortColumn$.next(value)
}
columnTemplates$: Observable<Record<string, TemplateRef<any> | null>> | undefined
columnFilterTemplates$: Observable<Record<string, TemplateRef<any> | null>> | undefined
_columns$ = new BehaviorSubject<DataTableColumn[]>([])
@Input()
get columns(): DataTableColumn[] {
Expand All @@ -134,9 +135,13 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
set columns(value: DataTableColumn[]) {
this._columns$.next(value)
const obs = value.map((c) => this.getTemplate(c, TemplateType.CELL))
const filterObs = value.map((c) => this.getTemplate(c, TemplateType.FILTERCELL))
this.columnTemplates$ = combineLatest(obs).pipe(
map((values) => Object.fromEntries(value.map((c, i) => [c.id, values[i]])))
)
this.columnFilterTemplates$ = combineLatest(filterObs).pipe(
map((values) => Object.fromEntries(value.map((c, i) => [c.id, values[i]])))
)
}
@Input() clientSideFiltering = true
@Input() clientSideSorting = true
Expand Down Expand Up @@ -783,18 +788,44 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon

filterTemplatesData: TemplatesData = {
templatesObservables: {},
idSuffix: ['IdTableFilterCell', 'IdFilterCell'],
idSuffix: ['IdTableFilterCell', 'IdFilterCell', 'IdTableCell', 'IdCell'],
templateNames: {
[ColumnType.DATE]: ['dateFilterCell', 'dateTableFilterCell', 'defaultDateCell'],
[ColumnType.NUMBER]: ['numberFilterCell', 'numberTableFilterCell', 'defaultNumberCell'],
[ColumnType.RELATIVE_DATE]: ['relativeDateFilterCell', 'relativeDateTableFilterCell', 'defaultRelativeDateCell'],
[ColumnType.DATE]: ['dateFilterCell', 'dateTableFilterCell', 'dateCell', 'dateTableCell', 'defaultDateCell'],
[ColumnType.NUMBER]: [
'numberFilterCell',
'numberTableFilterCell',
'numberCell',
'numberTableCell',
'defaultNumberCell',
],
[ColumnType.RELATIVE_DATE]: [
'relativeDateFilterCell',
'relativeDateTableFilterCell',
'relativeDateCell',
'relativeDateTableCell',
'defaultRelativeDateCell',
],
[ColumnType.TRANSLATION_KEY]: [
'translationKeyFilterCell',
'translationKeyTableFilterCell',
'defaultTranslationKeyCell',
'translationKeyCell',
'translationKeyTableCell',
],
[ColumnType.CUSTOM]: [
'customFilterCell',
'customTableFilterCell',
'customCell',
'customTableCell',
'defaultCustomCell',
],
[ColumnType.STRING]: [
'stringFilterCell',
'stringTableFilterCell',
'stringCell',
'stringTableCell',
'defaultStringCell',
],
[ColumnType.CUSTOM]: ['customFilterCell', 'customTableFilterCell', 'defaultCustomCell'],
[ColumnType.STRING]: ['stringFilterCell', 'stringTableFilterCell', 'defaultStringCell'],
},
}

Expand Down
Loading