ngx-column-filter-popup 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DOCUMENTATION.md +180 -5
- package/GETTING_STARTED.md +736 -0
- package/README.md +182 -15
- package/USAGE_EXAMPLES.md +134 -0
- package/package.json +2 -1
- package/src/app/components/column-filter/column-filter.component.html +22 -7
- package/src/app/components/column-filter/column-filter.component.scss +25 -0
- package/src/app/components/column-filter/column-filter.component.ts +76 -10
package/DOCUMENTATION.md
CHANGED
|
@@ -24,11 +24,12 @@ This is a **reusable Angular column filter component** that provides advanced fi
|
|
|
24
24
|
- **Match All Rules** (AND Logic): When multiple rules exist, **all rules** must match
|
|
25
25
|
- **Match Any Rule** (OR Logic): When multiple rules exist, **any one rule** can match (Default)
|
|
26
26
|
|
|
27
|
-
5. **Visual Feedback**:
|
|
28
|
-
6. **
|
|
29
|
-
7. **
|
|
30
|
-
8. **
|
|
31
|
-
9. **
|
|
27
|
+
5. **Visual Feedback**: Blinking red filter icon with X mark when active - smooth animation clearly indicates applied filters
|
|
28
|
+
6. **Backend Mode**: Send filter payloads directly to your backend API instead of filtering locally
|
|
29
|
+
7. **Fully Customizable**: Easily configure according to your data
|
|
30
|
+
8. **Single Filter Open**: Only one filter dropdown can be open at a time
|
|
31
|
+
9. **ESC Key Support**: Press ESC to close the open filter
|
|
32
|
+
10. **Programmatic Control**: Clear filters programmatically using `clearFilter()` method
|
|
32
33
|
|
|
33
34
|
---
|
|
34
35
|
|
|
@@ -608,6 +609,178 @@ const matches = itemMatchesFilter(
|
|
|
608
609
|
|
|
609
610
|
---
|
|
610
611
|
|
|
612
|
+
## Backend Mode (Backend API Integration)
|
|
613
|
+
|
|
614
|
+
### What is Backend Mode?
|
|
615
|
+
|
|
616
|
+
When `backendMode` is enabled, the component **does not apply any frontend filtering**. Instead, it collects all filter values and emits them as a structured payload ready to be sent to your backend API.
|
|
617
|
+
|
|
618
|
+
### When to Use Backend Mode:
|
|
619
|
+
|
|
620
|
+
- ✅ When you have large datasets and want server-side filtering
|
|
621
|
+
- ✅ When your filtering logic is complex and handled by backend
|
|
622
|
+
- ✅ When you need to send filter parameters to a REST API
|
|
623
|
+
- ✅ When combining frontend filters (some columns) with backend filters (other columns)
|
|
624
|
+
|
|
625
|
+
### How to Use Backend Mode:
|
|
626
|
+
|
|
627
|
+
**1. Enable backend mode on specific columns:**
|
|
628
|
+
|
|
629
|
+
```html
|
|
630
|
+
<lib-column-filter
|
|
631
|
+
columnName="first name"
|
|
632
|
+
columnKey="firstName"
|
|
633
|
+
[backendMode]="true"
|
|
634
|
+
(filterApplied)="onFilterApplied('firstName', $event)"
|
|
635
|
+
(filterCleared)="onFilterCleared('firstName')">
|
|
636
|
+
</lib-column-filter>
|
|
637
|
+
|
|
638
|
+
<lib-column-filter
|
|
639
|
+
columnName="email"
|
|
640
|
+
columnKey="email"
|
|
641
|
+
[backendMode]="true"
|
|
642
|
+
(filterApplied)="onFilterApplied('email', $event)"
|
|
643
|
+
(filterCleared)="onFilterCleared('email')">
|
|
644
|
+
</lib-column-filter>
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
**2. Use generic handlers with Map-based storage:**
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
import { Component } from '@angular/core';
|
|
651
|
+
import { ColumnFilterComponent } from 'ngx-column-filter-popup';
|
|
652
|
+
import { FilterConfig } from 'ngx-column-filter-popup';
|
|
653
|
+
|
|
654
|
+
@Component({
|
|
655
|
+
selector: 'app-example',
|
|
656
|
+
imports: [ColumnFilterComponent],
|
|
657
|
+
template: `<!-- HTML from above -->`
|
|
658
|
+
})
|
|
659
|
+
export class ExampleComponent {
|
|
660
|
+
// Unified filter storage
|
|
661
|
+
filters = new Map<string, FilterConfig | null>();
|
|
662
|
+
|
|
663
|
+
// Configuration: Which columns use backend mode
|
|
664
|
+
readonly backendModeColumns = new Set<string>(['firstName', 'email']);
|
|
665
|
+
|
|
666
|
+
// Generic filter handler
|
|
667
|
+
onFilterApplied(columnKey: string, filterConfig: FilterConfig) {
|
|
668
|
+
this.filters.set(columnKey, filterConfig);
|
|
669
|
+
|
|
670
|
+
if (this.isBackendMode(columnKey)) {
|
|
671
|
+
this.sendAllBackendFiltersToBackend();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
onFilterCleared(columnKey: string) {
|
|
676
|
+
this.filters.set(columnKey, null);
|
|
677
|
+
|
|
678
|
+
if (this.isBackendMode(columnKey)) {
|
|
679
|
+
this.sendAllBackendFiltersToBackend();
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
isBackendMode(columnKey: string): boolean {
|
|
684
|
+
return this.backendModeColumns.has(columnKey);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private sendAllBackendFiltersToBackend() {
|
|
688
|
+
const activeFilters: Array<{
|
|
689
|
+
field: string;
|
|
690
|
+
matchType: string;
|
|
691
|
+
value: string;
|
|
692
|
+
fieldType: string;
|
|
693
|
+
}> = [];
|
|
694
|
+
|
|
695
|
+
// Collect all active backend filters
|
|
696
|
+
this.backendModeColumns.forEach(columnKey => {
|
|
697
|
+
const filterConfig = this.filters.get(columnKey);
|
|
698
|
+
if (filterConfig && filterConfig.rules.length > 0) {
|
|
699
|
+
filterConfig.rules.forEach(rule => {
|
|
700
|
+
if (rule.value && rule.value.trim() !== '') {
|
|
701
|
+
activeFilters.push({
|
|
702
|
+
field: columnKey,
|
|
703
|
+
matchType: rule.matchType,
|
|
704
|
+
value: rule.value.trim(),
|
|
705
|
+
fieldType: filterConfig.fieldType || 'text'
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
const payload = {
|
|
713
|
+
activeFilters: activeFilters,
|
|
714
|
+
count: activeFilters.length
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// Send to your backend API
|
|
718
|
+
// this.httpClient.post('/api/filters', payload).subscribe({
|
|
719
|
+
// next: (response) => {
|
|
720
|
+
// this.filteredData = response.data;
|
|
721
|
+
// }
|
|
722
|
+
// });
|
|
723
|
+
|
|
724
|
+
console.log('Backend payload:', payload);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
### Backend Payload Format:
|
|
730
|
+
|
|
731
|
+
The component emits filter data in this format:
|
|
732
|
+
|
|
733
|
+
```json
|
|
734
|
+
{
|
|
735
|
+
"activeFilters": [
|
|
736
|
+
{
|
|
737
|
+
"field": "firstName",
|
|
738
|
+
"matchType": "contains",
|
|
739
|
+
"value": "John",
|
|
740
|
+
"fieldType": "text"
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
"field": "email",
|
|
744
|
+
"matchType": "contains",
|
|
745
|
+
"value": "example",
|
|
746
|
+
"fieldType": "text"
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
"count": 2
|
|
750
|
+
}
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
### Mixed Mode (Frontend + Backend):
|
|
754
|
+
|
|
755
|
+
You can use both frontend and backend filters together:
|
|
756
|
+
|
|
757
|
+
```typescript
|
|
758
|
+
// Some columns use frontend filtering
|
|
759
|
+
<lib-column-filter columnKey="lastName" [backendMode]="false" ...>
|
|
760
|
+
|
|
761
|
+
// Other columns use backend filtering
|
|
762
|
+
<lib-column-filter columnKey="firstName" [backendMode]="true" ...>
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
In `applyAllFilters()`, skip backend mode columns:
|
|
766
|
+
|
|
767
|
+
```typescript
|
|
768
|
+
private applyAllFilters() {
|
|
769
|
+
let result = [...this.originalData];
|
|
770
|
+
|
|
771
|
+
this.filters.forEach((filterConfig, columnKey) => {
|
|
772
|
+
// Skip backend mode columns (handled by backend)
|
|
773
|
+
if (filterConfig && !this.isBackendMode(columnKey)) {
|
|
774
|
+
result = applyColumnFilter(result, columnKey, filterConfig);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
this.filteredData = result;
|
|
779
|
+
}
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
---
|
|
783
|
+
|
|
611
784
|
## Programmatic Control
|
|
612
785
|
|
|
613
786
|
### Clearing Filters Programmatically
|
|
@@ -680,6 +853,8 @@ export class ExampleComponent {
|
|
|
680
853
|
✅ **What it does**: Provides advanced column filtering for tables/lists
|
|
681
854
|
✅ **Data adaptation**: Simply update `columnKey` and `columnName` in HTML
|
|
682
855
|
✅ **Match All Rules**: Feature to combine multiple rules with AND/OR logic
|
|
856
|
+
✅ **Backend Mode**: Send filter payloads directly to backend API
|
|
857
|
+
✅ **Visual Feedback**: Blinking red icon clearly indicates active filters
|
|
683
858
|
✅ **Easy to Use**: Simple API, fully customizable
|
|
684
859
|
✅ **Multiple Field Types**: Support for text, currency, age, date, and status fields
|
|
685
860
|
✅ **Programmatic Control**: Clear filters programmatically
|