ngx-column-filter-popup 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/README.md +169 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -75,6 +75,8 @@ npm install ngx-column-filter-popup
75
75
 
76
76
  ### Standalone Component (Angular 14+)
77
77
 
78
+ #### Basic Example:
79
+
78
80
  ```typescript
79
81
  import { Component } from '@angular/core';
80
82
  import { ColumnFilterComponent } from 'ngx-column-filter-popup';
@@ -105,6 +107,173 @@ export class ExampleComponent {
105
107
  }
106
108
  ```
107
109
 
110
+ #### Complete Example with New Features (Backend Mode, allowMultipleRules):
111
+
112
+ ```typescript
113
+ import { Component, ViewChildren, QueryList } from '@angular/core';
114
+ import { ColumnFilterComponent } from 'ngx-column-filter-popup';
115
+ import { FilterConfig, applyColumnFilter } from 'ngx-column-filter-popup';
116
+
117
+ interface User {
118
+ id: number;
119
+ firstName: string;
120
+ lastName: string;
121
+ email: string;
122
+ }
123
+
124
+ @Component({
125
+ selector: 'app-example',
126
+ imports: [ColumnFilterComponent],
127
+ template: `
128
+ <table>
129
+ <thead>
130
+ <tr>
131
+ <th>
132
+ First Name
133
+ <lib-column-filter
134
+ columnName="first name"
135
+ columnKey="firstName"
136
+ [allowMultipleRules]="false"
137
+ [backendMode]="isBackendMode('firstName')"
138
+ (filterApplied)="onFilterApplied('firstName', $event)"
139
+ (filterCleared)="onFilterCleared('firstName')">
140
+ </lib-column-filter>
141
+ </th>
142
+ <th>
143
+ Last Name
144
+ <lib-column-filter
145
+ columnName="last name"
146
+ columnKey="lastName"
147
+ [allowMultipleRules]="true"
148
+ [backendMode]="isBackendMode('lastName')"
149
+ (filterApplied)="onFilterApplied('lastName', $event)"
150
+ (filterCleared)="onFilterCleared('lastName')">
151
+ </lib-column-filter>
152
+ </th>
153
+ <th>
154
+ Email
155
+ <lib-column-filter
156
+ columnName="email"
157
+ columnKey="email"
158
+ [backendMode]="isBackendMode('email')"
159
+ (filterApplied)="onFilterApplied('email', $event)"
160
+ (filterCleared)="onFilterCleared('email')">
161
+ </lib-column-filter>
162
+ </th>
163
+ </tr>
164
+ </thead>
165
+ <tbody>
166
+ <tr *ngFor="let user of filteredUsers">
167
+ <td>{{ user.firstName }}</td>
168
+ <td>{{ user.lastName }}</td>
169
+ <td>{{ user.email }}</td>
170
+ </tr>
171
+ </tbody>
172
+ </table>
173
+ <button (click)="clearAllFilters()">Clear All Filters</button>
174
+ `
175
+ })
176
+ export class ExampleComponent {
177
+ originalData: User[] = [
178
+ { id: 1, firstName: 'John', lastName: 'Doe', email: 'john@example.com' }
179
+ ];
180
+ filteredData: User[] = [...this.originalData];
181
+
182
+ // ✅ Unified filter storage - single source of truth
183
+ filters = new Map<string, FilterConfig | null>();
184
+
185
+ // ✅ Configuration: Which columns use backend mode
186
+ readonly backendModeColumns = new Set<string>(['firstName', 'email']);
187
+
188
+ @ViewChildren(ColumnFilterComponent) filterComponents!: QueryList<ColumnFilterComponent>;
189
+
190
+ // ✅ Generic filter handler - works for all columns
191
+ onFilterApplied(columnKey: string, filterConfig: FilterConfig) {
192
+ this.filters.set(columnKey, filterConfig);
193
+
194
+ if (this.isBackendMode(columnKey)) {
195
+ this.sendAllBackendFiltersToBackend();
196
+ }
197
+
198
+ this.applyAllFilters();
199
+ }
200
+
201
+ // ✅ Generic filter clear handler
202
+ onFilterCleared(columnKey: string) {
203
+ this.filters.set(columnKey, null);
204
+
205
+ if (this.isBackendMode(columnKey)) {
206
+ this.sendAllBackendFiltersToBackend();
207
+ }
208
+
209
+ this.applyAllFilters();
210
+ }
211
+
212
+ // ✅ Check if column uses backend mode
213
+ isBackendMode(columnKey: string): boolean {
214
+ return this.backendModeColumns.has(columnKey);
215
+ }
216
+
217
+ // ✅ Apply all filters - automatically skips backend mode columns
218
+ private applyAllFilters() {
219
+ let result = [...this.originalData];
220
+
221
+ this.filters.forEach((filterConfig, columnKey) => {
222
+ // Skip backend mode columns (handled by backend)
223
+ if (filterConfig && !this.isBackendMode(columnKey)) {
224
+ result = applyColumnFilter(result, columnKey, filterConfig);
225
+ }
226
+ });
227
+
228
+ this.filteredData = result;
229
+ }
230
+
231
+ // ✅ Clear all filters programmatically
232
+ clearAllFilters() {
233
+ this.filters.clear();
234
+ this.sendAllBackendFiltersToBackend();
235
+ this.filteredData = [...this.originalData];
236
+
237
+ // Clear UI state in all filter components (icons/inputs)
238
+ if (this.filterComponents) {
239
+ this.filterComponents.forEach((filter: ColumnFilterComponent) => {
240
+ filter.clearFilter();
241
+ });
242
+ }
243
+ }
244
+
245
+ // ✅ Send all backend filters to API
246
+ private sendAllBackendFiltersToBackend() {
247
+ const activeFilters: Array<{
248
+ field: string;
249
+ matchType: string;
250
+ value: string;
251
+ fieldType: string;
252
+ }> = [];
253
+
254
+ this.backendModeColumns.forEach(columnKey => {
255
+ const filterConfig = this.filters.get(columnKey);
256
+ if (filterConfig && filterConfig.rules.length > 0) {
257
+ filterConfig.rules.forEach(rule => {
258
+ if (rule.value && rule.value.trim() !== '') {
259
+ activeFilters.push({
260
+ field: columnKey,
261
+ matchType: rule.matchType,
262
+ value: rule.value.trim(),
263
+ fieldType: filterConfig.fieldType || 'text'
264
+ });
265
+ }
266
+ });
267
+ }
268
+ });
269
+
270
+ const payload = { activeFilters, count: activeFilters.length };
271
+ // Send to your backend API
272
+ console.log('Backend payload:', payload);
273
+ }
274
+ }
275
+ ```
276
+
108
277
  ### Module-Based (Optional)
109
278
 
110
279
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-column-filter-popup",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A powerful, reusable Angular column filter component with support for multiple field types, advanced filtering rules, and customizable match modes",
5
5
  "keywords": [
6
6
  "angular",