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: filter options computed correctly #596

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
@@ -153,42 +153,44 @@
[title]="(sortIconTitle(column.id) | translate)"
[attr.aria-label]="('OCX_DATA_TABLE.TOGGLE_BUTTON.ARIA_LABEL' | translate: { column: (column.nameKey | translate), direction: (sortDirectionToTitle(columnNextSortDirection(column.id)) | translate)})"
></button>
<p-multiSelect
class="filterMultiSelect"
*ngIf="column.filterable && (!column.filterType || column.filterType === FilterType.EQUAL)"
[options]="(currentEqualFilterOptions$ | async) || []"
[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="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]="{
rowObject: getRowObjectFromMultiselectItem(value, column),
column: column
}"
>
</ng-container>
</ng-template>
</p-multiSelect>
>
</ng-container>
</ng-template>
</p-multiSelect>
</ng-container>
<p-multiSelect
class="filterMultiSelect"
*ngIf="column.filterable && column.filterType === FilterType.TRUTHY"
Original file line number Diff line number Diff line change
@@ -316,7 +316,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
selectedRows$: Observable<unknown[]> | undefined

currentFilterColumn$ = new BehaviorSubject<DataTableColumn | null>(null)
currentEqualFilterOptions$: Observable<SelectItem[]> | undefined
currentEqualFilterOptions$: Observable<{ options: SelectItem[]; column: DataTableColumn | undefined }> | undefined
currentEqualSelectedFilters$: Observable<unknown[]> | undefined
truthyFilterOptions = [
{
@@ -459,7 +459,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
),
mergeMap(([rows, currentFilterColumn, filters]) => {
if (!currentFilterColumn?.id) {
return of([])
return of({ options: [], column: undefined })
}

const currentFilters = filters
@@ -487,6 +487,12 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
value: filterOption,
}) as SelectItem
)
}),
map((options) => {
return {
options: options,
column: currentFilterColumn,
}
})
)
})