Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit e9664e0

Browse files
committed
feat: rename SG editorClass & deprecate internalColumnEditor
1 parent b5d6191 commit e9664e0

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
BackendServiceApi,
2222
BackendServiceOption,
2323
Column,
24-
ColumnEditor,
2524
DataViewOption,
2625
EventSubscription,
2726
ExternalResource,
@@ -1107,19 +1106,23 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
11071106

11081107
/** Load the Editor Collection asynchronously and replace the "collection" property when Observable resolves */
11091108
protected loadEditorCollectionAsync(column: Column) {
1110-
const collectionAsync = column && column.editor && (column.editor as ColumnEditor).collectionAsync;
1111-
if (collectionAsync instanceof Observable) {
1112-
this.subscriptions.push(
1113-
collectionAsync.subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection))
1114-
);
1115-
} else if (collectionAsync instanceof Promise) {
1116-
// wait for the "collectionAsync", once resolved we will save it into the "collection"
1117-
// the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
1118-
collectionAsync.then((response: any | any[]) => {
1119-
if (Array.isArray(response)) {
1120-
this.updateEditorCollection(column, response); // from Promise
1121-
}
1122-
});
1109+
if (column?.editor) {
1110+
const collectionAsync = column.editor.collectionAsync;
1111+
column.editor.disabled = true; // disable the Editor DOM element, we'll re-enable it after receiving the collection with "updateEditorCollection()"
1112+
1113+
if (collectionAsync instanceof Observable) {
1114+
this.subscriptions.push(
1115+
collectionAsync.subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection))
1116+
);
1117+
} else if (collectionAsync instanceof Promise) {
1118+
// wait for the "collectionAsync", once resolved we will save it into the "collection"
1119+
// the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
1120+
collectionAsync.then((response: any | any[]) => {
1121+
if (Array.isArray(response)) {
1122+
this.updateEditorCollection(column, response); // from Promise
1123+
}
1124+
});
1125+
}
11231126
}
11241127
}
11251128

@@ -1420,7 +1423,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
14201423
if (column?.editor?.collectionAsync) {
14211424
this.loadEditorCollectionAsync(column);
14221425
}
1423-
return { ...column, editor: column.editor?.model, internalColumnEditor: { ...column.editor } };
1426+
return { ...column, editorClass: column.editor?.model, internalColumnEditor: { ...column.editor } };
14241427
});
14251428
}
14261429

@@ -1430,23 +1433,25 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
14301433
* Once we found the new pointer, we will reassign the "editor" and "collection" to the "internalColumnEditor" so it has newest collection
14311434
*/
14321435
protected updateEditorCollection<T = any>(column: Column<T>, newCollection: T[]) {
1433-
(column.editor as ColumnEditor).collection = newCollection;
1434-
(column.editor as ColumnEditor).disabled = false;
1435-
1436-
// find the new column reference pointer & re-assign the new editor to the internalColumnEditor
1437-
if (Array.isArray(this.columnDefinitions)) {
1438-
const columnRef = this.columnDefinitions.find((col: Column) => col.id === column.id);
1439-
if (columnRef) {
1440-
columnRef.internalColumnEditor = column.editor as ColumnEditor;
1436+
if (this.slickGrid && column.editor) {
1437+
column.editor.collection = newCollection;
1438+
column.editor.disabled = false;
1439+
1440+
// find the new column reference pointer & re-assign the new editor to the internalColumnEditor
1441+
if (Array.isArray(this.columnDefinitions)) {
1442+
const columnRef = this.columnDefinitions.find((col: Column) => col.id === column.id);
1443+
if (columnRef) {
1444+
columnRef.internalColumnEditor = column.editor;
1445+
}
14411446
}
1442-
}
14431447

1444-
// get current Editor, remove it from the DOM then re-enable it and re-render it with the new collection.
1445-
const currentEditor = this.slickGrid.getCellEditor() as AutocompleterEditor | SelectEditor;
1446-
if (currentEditor?.disable && currentEditor?.renderDomElement) {
1447-
currentEditor.destroy();
1448-
currentEditor.disable(false);
1449-
currentEditor.renderDomElement(newCollection);
1448+
// get current Editor, remove it from the DOM then re-enable it and re-render it with the new collection.
1449+
const currentEditor = this.slickGrid.getCellEditor() as AutocompleterEditor | SelectEditor;
1450+
if (currentEditor?.disable && currentEditor?.renderDomElement) {
1451+
currentEditor.destroy();
1452+
currentEditor.disable(false);
1453+
currentEditor.renderDomElement(newCollection);
1454+
}
14501455
}
14511456
}
14521457
}

0 commit comments

Comments
 (0)