Skip to content

Commit

Permalink
refactor(table-service): primefaces#15009 improve signature
Browse files Browse the repository at this point in the history
  • Loading branch information
juri-sinitson committed Nov 21, 2024
1 parent 90d17ad commit 782b134
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/primeng/src/api/fitlersarg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FilterMetadata } from './filtermetadata';

export type FiltersArg = { [key: string]: FilterMetadata | FilterMetadata[] | string };
20 changes: 11 additions & 9 deletions packages/primeng/src/table/table.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Injectable } from '@angular/core';
import { resolveFieldData } from '@primeuix/utils';
import { Subject } from 'rxjs';

import { FilterMatchMode, FilterMetadata, FilterOperator, FilterService, SortMeta } from 'primeng/api';

import { Subject } from 'rxjs';
import { FiltersArg } from '../api/fitlersarg';

@Injectable()
export class TableService {
Expand Down Expand Up @@ -46,14 +48,14 @@ export class TableService {
this.columnsSource.next(columns);
}

filter(value: any[], filters: any, globalFilterFieldsArray: any[], filterLocale: string | undefined): any[] {
if (!value || value.length === 0 || !filters || Object.keys(filters).length === 0) {
return value;
filter(data: any[], filters: FiltersArg, globalFilterFieldsArray: any[], filterLocale: string | undefined): any[] {
if (!data || data.length === 0 || !filters || Object.keys(filters).length === 0) {
return data;
}

let filteredValue = [];

for (let i = 0; i < value.length; i++) {
for (let i = 0; i < data.length; i++) {
let localMatch = true;
let globalMatch = false;
let localFiltered = false;
Expand All @@ -66,14 +68,14 @@ export class TableService {

if (Array.isArray(filterMeta)) {
for (let meta of filterMeta) {
localMatch = this.executeLocalFilter(filterField, value[i], meta, filterLocale);
localMatch = this.executeLocalFilter(filterField, data[i], meta, filterLocale);

if ((meta.operator === FilterOperator.OR && localMatch) || (meta.operator === FilterOperator.AND && !localMatch)) {
break;
}
}
} else {
localMatch = this.executeLocalFilter(filterField, value[i], <any>filterMeta, filterLocale);
localMatch = this.executeLocalFilter(filterField, data[i], <any>filterMeta, filterLocale);
}

if (!localMatch) {
Expand All @@ -85,7 +87,7 @@ export class TableService {
if (filters['global'] && !globalMatch && globalFilterFieldsArray) {
for (let j = 0; j < globalFilterFieldsArray.length; j++) {
let globalFilterField = globalFilterFieldsArray[j].field || globalFilterFieldsArray[j];
globalMatch = (<any>this.filterService).filters[(<any>filters['global']).matchMode](resolveFieldData(value[i], globalFilterField), (<FilterMetadata>filters['global']).value, filterLocale);
globalMatch = (<any>this.filterService).filters[(<any>filters['global']).matchMode](resolveFieldData(data[i], globalFilterField), (<FilterMetadata>filters['global']).value, filterLocale);

if (globalMatch) {
break;
Expand All @@ -101,7 +103,7 @@ export class TableService {
}

if (matches) {
filteredValue.push(value[i]);
filteredValue.push(data[i]);
}
}

Expand Down

0 comments on commit 782b134

Please sign in to comment.