Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit baf4d93

Browse files
Reset value of nested components (#1021)
* Reset value of nested components * Fix lint
1 parent ac72c87 commit baf4d93

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

src/core/nested-option.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export abstract class BaseNestedOption implements INestedOptionContainer, IColle
6464
}
6565
}
6666

67+
protected _resetOption(name: string) {
68+
this.instance.resetOption(name);
69+
}
70+
6771
setHost(host: INestedOptionContainer, optionPath: IOptionPathGetter) {
6872
this._host = host;
6973
this._hostOptionPath = optionPath;

templates/nested-component.tst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<#? it.inputs #>/* tslint:disable:use-input-property-decorator */
44
<#?#>
55
import {
6-
Component,
6+
Component,<#? !it.isCollection #>
7+
OnDestroy,<#?#>
78
NgModule,
89
Host,<#? it.hasTemplate #>
910
ElementRef,
@@ -44,7 +45,8 @@ import { <#= it.baseClass #> } from '<#= it.basePath #>';
4445
'<#= input.name #>'<#? i < it.inputs.length-1 #>,<#?#><#~#>
4546
]<#?#>
4647
})
47-
export class <#= it.className #>Component extends <#= it.baseClass #><#? it.hasTemplate #> implements AfterViewInit, IDxTemplateHost<#?#> {<#~ it.properties :prop:i #>
48+
export class <#= it.className #>Component extends <#= it.baseClass #><#? it.hasTemplate #> implements AfterViewInit,<#? !it.isCollection #> OnDestroy,<#?#>
49+
IDxTemplateHost<#?#><#? !it.isCollection && !it.hasTemplate #> implements OnDestroy <#?#> {<#~ it.properties :prop:i #>
4850
@Input()
4951
get <#= prop.name #>(): <#= prop.type #> {
5052
return this._getOption('<#= prop.name #>');
@@ -103,6 +105,11 @@ export class <#= it.className #>Component extends <#= it.baseClass #><#? it.hasT
103105
extractTemplate(this, this.element, this.renderer, this.document);
104106
}
105107
<#?#>
108+
<#? !it.isCollection #>
109+
ngOnDestroy() {
110+
this._resetOption(this._optionPath);
111+
}
112+
<#?#>
106113
}
107114

108115
@NgModule({

tests/src/server/component-names.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ export const componentNames = [
1616
'data-grid',
1717
'date-box',
1818
'defer-rendering',
19+
'diagram',
20+
'draggable',
1921
'drawer',
2022
'drop-down-box',
2123
'drop-down-button',
24+
'file-manager',
2225
'file-uploader',
2326
'filter-builder',
2427
'form',
2528
'funnel',
2629
'gallery',
30+
'gantt',
2731
'html-editor',
2832
'linear-gauge',
2933
'list',
@@ -55,6 +59,7 @@ export const componentNames = [
5559
'slide-out',
5660
'slide-out-view',
5761
'slider',
62+
'sortable',
5863
'sparkline',
5964
'speed-dial-action',
6065
'switch',

tests/src/ui/data-grid.spec.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import DxDataGrid from 'devextreme/ui/data_grid';
2222
template: ''
2323
})
2424
class TestContainerComponent {
25+
showComponent = true;
2526
dataSource = [{
2627
id: 1,
2728
string: 'String',
@@ -113,8 +114,8 @@ describe('DxDataGrid', () => {
113114
TestBed.overrideComponent(TestContainerComponent, {
114115
set: {
115116
template: `
116-
<dx-data-grid
117-
[columns]="['obj.field']"
117+
<dx-data-grid
118+
[columns]="['obj.field']"
118119
[dataSource]="dataSourceWithUndefined">
119120
</dx-data-grid>`
120121
}
@@ -206,6 +207,34 @@ describe('DxDataGrid', () => {
206207
jasmine.clock().uninstall();
207208
});
208209

210+
it('should reset nested option', () => {
211+
TestBed.overrideComponent(TestContainerComponent, {
212+
set: {
213+
template: `<dx-data-grid [dataSource]="[{text: 'text'}]">
214+
<dxo-column-chooser *ngIf="showComponent" [enabled]="true"></dxo-column-chooser>
215+
<dxi-column dataField="text"></dxi-column>
216+
</dx-data-grid>`
217+
}
218+
});
219+
220+
jasmine.clock().uninstall();
221+
jasmine.clock().install();
222+
223+
let fixture = TestBed.createComponent(TestContainerComponent);
224+
225+
fixture.detectChanges();
226+
227+
jasmine.clock().tick(101);
228+
let testComponent = fixture.componentInstance;
229+
const instance = testComponent.innerWidgets.last.instance;
230+
expect(instance.option('columnChooser').enabled).toBe(true);
231+
232+
testComponent.showComponent = false;
233+
fixture.detectChanges();
234+
expect(instance.option('columnChooser').enabled).toBe(false);
235+
jasmine.clock().uninstall();
236+
});
237+
209238
it('should destroy devextreme components in template correctly', () => {
210239
@Component({
211240
selector: 'test-container-component',
@@ -274,7 +303,7 @@ describe('Nested DxDataGrid', () => {
274303
TestBed.overrideComponent(TestContainerComponent, {
275304
set: {
276305
template: `
277-
<dx-data-grid
306+
<dx-data-grid
278307
[dataSource]="dataSource"
279308
keyExpr="id"
280309
[masterDetail]="{ enabled: true, template: 'detail' }"
@@ -295,7 +324,7 @@ describe('Nested DxDataGrid', () => {
295324
<dxi-column dataField="string"></dxi-column>
296325
<dxi-column dataField="string"></dxi-column>
297326
<dxi-column dataField="string"></dxi-column>
298-
327+
299328
<div *dxTemplate="let data of 'detail'">
300329
<dx-data-grid [dataSource]="dataSource">
301330
<dxi-column dataField="number"></dxi-column>

0 commit comments

Comments
 (0)