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

Ability to clear listbox filter #4680

Closed
orwtech opened this issue Dec 18, 2017 · 8 comments
Closed

Ability to clear listbox filter #4680

orwtech opened this issue Dec 18, 2017 · 8 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@orwtech
Copy link

orwtech commented Dec 18, 2017

There is no guarantee in receiving a response in GitHub Issue Tracker, If you'd like to secure our response, you may consider PrimeNG PRO Support where support is provided within 4 business hours

I'm submitting a bug report to Listbox component to be able to clear the filter input text when the listbox.filterValue is set to '', undefined, null... (check one with "x")

When listbox.filterValue = '' I would expect the component to react and clear the wrapped Input value.

Please advice on how to do this if this by design

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
Please fork the plunkr below and create a case demonstrating your bug report. Issues without a plunkr have much less possibility to be reviewed.

http://plnkr.co/edit/6q5v84DWolH6DeAdi70w?p=preview

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Angular version: 4.3.X
  • PrimeNG version: 2.0.X
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version =

@cagataycivici cagataycivici changed the title Setting Listbox.filterValue = '' does not clear filter input field Ability to clear listbox filter Dec 19, 2017
@cagataycivici cagataycivici added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Dec 19, 2017
@ochiers
Copy link

ochiers commented Jan 11, 2018

I have the same issue.

When my listbox's filter is set to a value and that I want to reset this,
I set the filterValue to an empty string then the old value is still display.

  • Angular version: 4.3.X

  • PrimeNG version: 4.3.X

Sorry for my english.

@petewins
Copy link

My work around was to use ViewChild and ElementRef to set input value to ' '. Please advise if there is a better solution

@orwtech
Copy link
Author

orwtech commented Apr 11, 2018

@petewins

Please share source on how to implement ViewChild and ElementRef work around

@petewins
Copy link

@orwtech, I have found a cleaner workaround, add ngIf to this component to reinitialize it when you want to empty the value. Since it is binded using ngModel, the data should not change.
html
<p-listbox *ngIf="listBox">
<a (click)=clearText()> clear

component
listbox = true
clearText() { ... this.listBox = false; setTimeout(() => (this.listBox = true), 0); }

@cagataycivici cagataycivici self-assigned this Oct 3, 2018
@cagataycivici cagataycivici added this to the 6.1.5 milestone Oct 3, 2018
@Merve7 Merve7 closed this as completed in e2f56db Oct 9, 2018
@schepuri2012
Copy link

I am using 7.1.3 release and I am still unable to clear the input filter value even after binding a model attribute it to the new "filterValue" attribute.

@tundisto
Copy link

tundisto commented Apr 17, 2020

@orwtech @schepuri2012

For those who still aren't able to clear the filter value:

HTML:

<p-listbox #myListbox [options]="myOptions" [(ngModel)]="myModel" [filter]="true"></p-listbox>

Code:

import { ViewChild } from '@angular/core';
import { Listbox } from 'primeng/listbox';

@Component({
  selector: 'my-component',
  templateUrl: './my-component.component.html'
})

export class MyComponent {

  @ViewChild('myListbox') myListboxComponent: Listbox;

  resetMethod() {
    // trigger me somewhere in your template
    this.myListboxComponent._filterValue = '';
  }

}

@zjs10443
Copy link

@tundisto this worked in 9.## but after upgrading to 12 its not working

@0m3rF
Copy link

0m3rF commented Apr 16, 2023

I am working with primeng 15.2.0 and below code has worked for me.

<button ... (click)="clearListboxFilter(listbox)"></button>
<p-listbox #listbox ... > </p-listbox>

clearListboxFilter(listbox: any) {
    listbox._filterValue = "";
    listbox.activateFilter();
    listbox.cd.detectChanges();
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

8 participants