Import these items from ngx-treeview library to the component:
import { TreeviewComponent, TreeviewConfig, TreeviewItem } from 'ngx-treeview';
Add this Global Variable to Typescript Code of the Component
@ViewChild(TreeviewComponent, { static: false }) treeviewComponent: TreeviewComponent;
- In Html, For the ngx-treeview HTML Tag, bind treeviewComponent
variable Declared as follows:
<ngx-treeview #treeviewComponent [config]="config" [items]="treeviewItems"
(selectedChange)="onSelectedChange($event)">
- Create a Button to Clear Filter and Bind it to a Click Event Method. In that Click Event Method, Add These Lines of Code(this is for 3 level treeviewitem list, Change it as per your code):
this.treeviewItems.forEach(level1 => { //level 1
level1.checked = false; //unchecks checkboxes
level1.children.forEach(level2 => { //level 2
level2.checked = false; //unchecks children checkboxes
level2.children.forEach(level3 => { //level 3
level3.checked = false;
});
});
});
this.treeviewComponent.onFilterTextChange('')
this.treeviewComponent.filterText = '';
this.treeviewItems = [...this.treeviewItems];
On Clicking The Clear Button, It should clear Filter Input Field as well as
All the Checked Checkboxes.