Angular 8, TurboTable: filterConstraint is not a function

UI Components for Angular
Post Reply
MickeyMiner
Posts: 11
Joined: 04 Jul 2017, 13:05

10 Sep 2019, 13:44

Hi,

I was creating custom filters like this:

Code: Select all

<p-table #dt [value]="allSettings" [(selection)]="selectedSetting">
     <ng-template pTemplate="caption">
          <p-selectButton [options]="keyFilters" (onChange)="onChangeMyFunction($event, dt)"
               [(ngModel)]="keyFilter"></p-selectButton>
     </ng-template>

Code: Select all

@ViewChild('dt', {static: false}) ttable: Table;

ngOnInit() {
     // This if I added in Angular 8 because this.ttable['filterConstraints'] because TypeError: Cannot set property 'containsNone' of undefined
     // In Angular 7 it was working event without this.
     if (!this.ttable['filterConstraints']) {
           this.ttable['filterConstraints'] = [];
     }

     this.ttable['filterConstraints']['containsNone'] = function containsNone (value: string, filter: string[]): boolean {
           console.log('ttable.filterConstraints.containsNone', value, filter);
           const result = someBusinessLogic();
           return result;
     };
}

onChangeMyFunction(event: any, grid: Table) {
    console.log('onChangeMyFunction() grid.filterConstraints = ', grid.filterConstraints);
    const value = event === null ? null : event.value;
    switch (value) {
    case 'none':
        grid.filter(['MONO_', 'YEXT_', 'BOOST_'], 'key', 'containsNone');
        break;
     default:
        grid.reset();
        break;
    }
}
After update to Angular 8.2.5 with PrimeNG 8.0.3 (from Angular 7.2.15) I get Following error:

Code: Select all

onChangeMyFunction() grid.filterConstraints =  [containsNone: f, containsAll: f]
core.js:6014 ERROR TypeError: filterConstraint is not a function
    at Table.push../node_modules/primeng/components/table/table.js.Table._filter (table.js:887)
    at table.js:830
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:39679)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)
    at Zone.runTask (zone-evergreen.js:168)
    at invokeTask (zone-evergreen.js:465)
    at ZoneTask.invoke (zone-evergreen.js:454)
    at timer (zone-evergreen.js:2650)
What should I do? Why is property this.ttable['filterConstraints'] undefined by default? Shouldn't there be something like "contains", "gt" and so on?

Thank you very much for your support!

MM

hugonoro
Posts: 10
Joined: 25 Jul 2018, 15:16

17 Oct 2019, 16:13

I'm also having issues with this after upgrading to primeng 8.0.4

I would like to upgrade to have the latest fixes in place, although I was using this property to define date range filtering on the tables. It's weird that we no longer have this option to create custom filters, specially when there a couple of simple scenarios that are not supported out of the box (date range).

Was this change intentional? Is there any other way to define custom filters?

vandanakm.del
Posts: 1
Joined: 07 Mar 2020, 12:41

07 Mar 2020, 12:54

Hi ,

Can someone please help on this. I am using primeng 6.0.2 and suddenly the custom filter on date column has stopped working.on selection of date range I get error- filterConstraint is not a function.earlier it used to work.

Thanks.

oowaratah
Posts: 2
Joined: 26 Apr 2020, 02:13

28 Oct 2020, 08:17

executeLocalFilter(field: string, rowData: any, filterMeta: FilterMetadata): boolean {
let filterValue = filterMeta.value;
let filterMatchMode = filterMeta.matchMode || FilterMatchMode.STARTS_WITH;
let dataFieldValue = ObjectUtils.resolveFieldData(rowData, field);
let filterConstraint = FilterUtils[filterMatchMode];

return filterConstraint(dataFieldValue, filterValue, this.filterLocale);
}

I am having problems here because my filter function is not reconfigured on reload but the filter is restored. possibly should return a no filter function on failure so that the application does not fail.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests