@eherve/angular-material-datatable 22.2.1 → 22.2.2
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/README.md
CHANGED
|
@@ -66,3 +66,25 @@ Set inherited CSS custom properties on the datatable or an application ancestor.
|
|
|
66
66
|
| `--ngx-mat-extended-on-accent` | Material on-primary | Selected header checkbox checkmark color. |
|
|
67
67
|
|
|
68
68
|
The counter sizes to its content and shares the toolbar button height; long counts remain fully visible. Header checkbox overrides include selected, focused, hovered, pressed and indeterminate states; disabled colors retain the Material theme defaults. Existing `--ngx-mat-datatable-*` color and sticky positioning properties remain supported.
|
|
69
|
+
|
|
70
|
+
## Restored autocomplete filters
|
|
71
|
+
|
|
72
|
+
Searchable autocomplete columns can supply `resolveOption(value: unknown): Promise<DatatableSearchListOption | null>`
|
|
73
|
+
to recover the display option for a restored filter containing only its stored value. The application owns the lookup
|
|
74
|
+
(API, cache or in-memory list); the table does not assume an endpoint. Return an option whose `value` matches the
|
|
75
|
+
requested value, including its label and optional color/group, or `null` when unavailable.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
resolveOption: async (value) => {
|
|
79
|
+
if (typeof value !== 'string') return null;
|
|
80
|
+
const item = await service.get(value);
|
|
81
|
+
return item ? { value: item._id, name: item.name } : null;
|
|
82
|
+
},
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Resolution runs after initialization or a programmatic value update, when the selected option is unknown. It does not
|
|
86
|
+
run for each search keystroke or for empty values. Known option labels are retained across suggestion searches. Late
|
|
87
|
+
responses after editing, clearing, replacing the filter or destroying the control are ignored. Lookup failures leave
|
|
88
|
+
the stored filter unchanged; successful resolution refreshes the input without emitting a filter change.
|
|
89
|
+
For columns with a resolver, an unresolved value is never displayed as raw text: the input stays blank until its label
|
|
90
|
+
is known, including when lookup fails or returns no option. Columns without a resolver keep their existing display.
|
|
@@ -972,15 +972,17 @@ var HeaderAutocompleteFilterComponent = class HeaderAutocompleteFilterComponent
|
|
|
972
972
|
injector = inject(Injector);
|
|
973
973
|
changeDetectorRef = inject(ChangeDetectorRef);
|
|
974
974
|
subsink = new Subscription();
|
|
975
|
+
viewInitialized = false;
|
|
976
|
+
resolutionVersion = 0;
|
|
977
|
+
selectedOption;
|
|
975
978
|
writeValue(value) {
|
|
976
979
|
if (value?.value !== this.selectControl.value) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
982
|
-
}
|
|
980
|
+
this.selectedOption = this.options.find((option) => option.value === value?.value) ?? (value?.name ? {
|
|
981
|
+
value: value.value,
|
|
982
|
+
name: value.name
|
|
983
|
+
} : void 0);
|
|
983
984
|
this.selectControl.setValue(value?.value, { emitEvent: false });
|
|
985
|
+
if (this.viewInitialized) this.resolveSelectedOption();
|
|
984
986
|
}
|
|
985
987
|
this.changeDetectorRef.markForCheck();
|
|
986
988
|
}
|
|
@@ -999,6 +1001,8 @@ var HeaderAutocompleteFilterComponent = class HeaderAutocompleteFilterComponent
|
|
|
999
1001
|
if (!ngControl) throw new Error(`${this.constructor.name} missing control [column:${this.column.columnDef}]`);
|
|
1000
1002
|
this.control = ngControl.control;
|
|
1001
1003
|
this.subsink.add(this.selectControl.valueChanges.subscribe((value) => {
|
|
1004
|
+
this.resolutionVersion++;
|
|
1005
|
+
this.selectedOption = this.options.find((option) => option.value === value) ?? this.selectedOption;
|
|
1002
1006
|
if (value === void 0) {
|
|
1003
1007
|
if (this.control.value !== void 0) this.onChange(void 0);
|
|
1004
1008
|
} else if (value === null && !this.options.find((o) => o.value === null)) {
|
|
@@ -1009,9 +1013,13 @@ var HeaderAutocompleteFilterComponent = class HeaderAutocompleteFilterComponent
|
|
|
1009
1013
|
});
|
|
1010
1014
|
}));
|
|
1011
1015
|
this.buildOptions();
|
|
1016
|
+
this.viewInitialized = true;
|
|
1017
|
+
this.resolveSelectedOption();
|
|
1012
1018
|
this.changeDetectorRef.detectChanges();
|
|
1013
1019
|
}
|
|
1014
1020
|
ngOnDestroy() {
|
|
1021
|
+
this.viewInitialized = false;
|
|
1022
|
+
this.resolutionVersion++;
|
|
1015
1023
|
this.subsink.unsubscribe();
|
|
1016
1024
|
}
|
|
1017
1025
|
loadMore(intersect) {
|
|
@@ -1025,15 +1033,45 @@ var HeaderAutocompleteFilterComponent = class HeaderAutocompleteFilterComponent
|
|
|
1025
1033
|
}
|
|
1026
1034
|
}
|
|
1027
1035
|
filter() {
|
|
1036
|
+
this.resolutionVersion++;
|
|
1028
1037
|
const search = this.input.nativeElement.value;
|
|
1029
1038
|
this.filter$.next(search);
|
|
1030
1039
|
}
|
|
1031
1040
|
displayWith = (value) => {
|
|
1032
|
-
|
|
1033
|
-
if (!this.options) val = value;
|
|
1034
|
-
else val = this.options.find((o) => o.value === value)?.name ?? value;
|
|
1035
|
-
return stripHtml(val);
|
|
1041
|
+
return stripHtml((this.options.find((option) => option.value === value) ?? (this.selectedOption?.value === value ? this.selectedOption : void 0))?.name ?? (this.column?.resolveOption ? "" : value));
|
|
1036
1042
|
};
|
|
1043
|
+
async resolveSelectedOption() {
|
|
1044
|
+
const version = ++this.resolutionVersion;
|
|
1045
|
+
const value = this.selectControl.value;
|
|
1046
|
+
if (this.isEmptyValue(value)) return;
|
|
1047
|
+
const known = this.options.find((option) => option.value === value) ?? (this.selectedOption?.value === value ? this.selectedOption : void 0);
|
|
1048
|
+
if (known) {
|
|
1049
|
+
this.applyResolvedOption(known);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (!this.column.resolveOption) return;
|
|
1053
|
+
try {
|
|
1054
|
+
const option = await this.column.resolveOption(value);
|
|
1055
|
+
if (!this.viewInitialized || version !== this.resolutionVersion || this.selectControl.value !== value || !option || option.value !== value) return;
|
|
1056
|
+
this.applyResolvedOption(option);
|
|
1057
|
+
} catch {}
|
|
1058
|
+
}
|
|
1059
|
+
applyResolvedOption(option) {
|
|
1060
|
+
this.selectedOption = option;
|
|
1061
|
+
this.addOption(option);
|
|
1062
|
+
this.selectControl.setValue(option.value, { emitEvent: false });
|
|
1063
|
+
this.changeDetectorRef.markForCheck();
|
|
1064
|
+
}
|
|
1065
|
+
addOption(option) {
|
|
1066
|
+
if (!this.options.some((existing) => existing.value === option.value)) this.options.push(option);
|
|
1067
|
+
const name = option.group ?? "";
|
|
1068
|
+
const group = this.groups.find((group) => group.name === name);
|
|
1069
|
+
if (!group) this.groups.push({
|
|
1070
|
+
name,
|
|
1071
|
+
options: [option]
|
|
1072
|
+
});
|
|
1073
|
+
else if (!group.options.some((existing) => existing.value === option.value)) group.options.push(option);
|
|
1074
|
+
}
|
|
1037
1075
|
getGlobalSearchValue() {
|
|
1038
1076
|
if (!this.control.parent) return null;
|
|
1039
1077
|
let parent = this.control.parent;
|
|
@@ -1054,16 +1092,7 @@ var HeaderAutocompleteFilterComponent = class HeaderAutocompleteFilterComponent
|
|
|
1054
1092
|
this.searching = false;
|
|
1055
1093
|
this.changeDetectorRef.markForCheck();
|
|
1056
1094
|
}))), filter((data) => Array.isArray(data)), map((data) => {
|
|
1057
|
-
data.forEach((
|
|
1058
|
-
this.options.push(d);
|
|
1059
|
-
const name = d.group ?? "";
|
|
1060
|
-
const group = this.groups.find((g) => g.name === name);
|
|
1061
|
-
if (!group) this.groups.push({
|
|
1062
|
-
name,
|
|
1063
|
-
options: [d]
|
|
1064
|
-
});
|
|
1065
|
-
else group.options.push(d);
|
|
1066
|
-
});
|
|
1095
|
+
data.forEach((option) => this.addOption(option));
|
|
1067
1096
|
skip += this.column.limit || 10;
|
|
1068
1097
|
this.hasMore = data.length === (this.column.limit || 10);
|
|
1069
1098
|
}));
|