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

Table filter set undefined #14588

Closed
certifirm opened this issue Jan 18, 2024 · 4 comments · Fixed by #15053
Closed

Table filter set undefined #14588

certifirm opened this issue Jan 18, 2024 · 4 comments · Fixed by #15053
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@certifirm
Copy link

certifirm commented Jan 18, 2024

Describe the bug

I am using table component with this filter box:

 <th>
          <input pInputText style="width: 100%;"
            (input)="employeesList.filter($event.target['value'], column.field, 'contains')"
            [value]="employeesList.filters[column.field]?.['value']">
 </th>

Using PrimeNG 17.3.0 all works well. With 17.3.1 and up, sets undefined in the inputbox when you write a character in it.

Environment

Angular 17
Prime 17.3.3

Reproducer

No response

Angular version

17

PrimeNG version

17.3.3

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v18.18.2

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

Work like in 17.3.0

@certifirm certifirm added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 18, 2024
@Da13Harris
Copy link

Da13Harris commented Jan 31, 2024

We are also encountering this bug in the latest release (17.4.0). It works in our previous version (16.0.2) of PrimeNG.

When typing anything into the filter, the word "undefined" appears in the text box. This issue appears to have been introduced by #14433, which fixed #14432, because the individual custom filters are now being nested inside an array. Unfortunately, this is a breaking change in a minor release.

Here's an example snippet of our code that has this issue:

<input
  id="network-name-filter"
  type="text"
  (input)="utilitiesService.tableFilter(tableRef, 'networkName', $event)"
  [value]="utilitiesService.castFilterAsMetadata(tableRef.filters['networkName'])?.value"
  placeholder="Filter Network Name"
/>

The utilitiesService.tableFilter() is a wrapper function that calls tableRef.filter(target.value, propertyName, matchMode), just like @certifirm's issue.

tableFilter(
  tableRef: Table,
  propertyName: string,
  event: Event,
  matchMode: string = FilterMatchMode.CONTAINS
) {
  const target =
    event.target instanceof HTMLInputElement
      ? event.target
      : (event.target as HTMLSelectElement);

  tableRef.filter(target.value, propertyName, matchMode as string);
}

The castFilterAsMetadata() method is just a TypeScript wrapper to cast the value as a FilterMetadata type.

castFilterAsMetadata(
  filter: FilterMetadata | FilterMetadata[] | undefined
): FilterMetadata | undefined {
  return filter as FilterMetadata;
}

@mylifeandcode
Copy link

Having this issue as well.

@cetincakiroglu
Copy link
Contributor

cetincakiroglu commented Mar 14, 2024

Hi @certifirm @Da13Harris,

I guess there was an unintended breaking change. Could you please provide a stackblitz example so we can identify and address the issue? I'm moving this to the next week's milestone until the reproducer arrives.

@cetincakiroglu cetincakiroglu modified the milestones: 17.11.0, 17.12.0 Mar 14, 2024
@cetincakiroglu cetincakiroglu added Resolution: Needs More Information More information about the issue is needed to find a correct solution and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Mar 14, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.12.0, 17.11.0 Mar 14, 2024
@cetincakiroglu
Copy link
Contributor

Fixed in #15053

@cetincakiroglu cetincakiroglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Resolution: Needs More Information More information about the issue is needed to find a correct solution labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants