diff --git a/packages/devextreme/js/__internal/grids/data_grid/export/m_export.ts b/packages/devextreme/js/__internal/grids/data_grid/export/m_export.ts index 6046b2918ed7..6ffc217942b0 100644 --- a/packages/devextreme/js/__internal/grids/data_grid/export/m_export.ts +++ b/packages/devextreme/js/__internal/grids/data_grid/export/m_export.ts @@ -608,11 +608,16 @@ export class ExportController extends dataGridCore.ViewController { return headersView && headersView.isVisible() ? headersView.getColumnWidths() : rowsView.getColumnWidths(); } - init() { - if (this.option('export.enabled') && !isDefined(this.option('onExporting'))) { + private throwWarningIfNoOnExportingEvent(): void { + const hasOnExporting = (this.component as any).hasActionSubscription?.('onExporting'); + + if (this.option('export.enabled') && !hasOnExporting) { errors.log('W1024'); } + } + init() { + this.throwWarningIfNoOnExportingEvent(); this._columnsController = this.getController('columns'); this._rowsView = this.getView('rowsView'); this._headersView = this.getView('columnHeadersView' as any); @@ -666,6 +671,13 @@ export class ExportController extends dataGridCore.ViewController { } } + optionChanged(args) { + super.optionChanged(args); + if (args.name === 'export') { + this.throwWarningIfNoOnExportingEvent(); + } + } + needLoadItemsOnExportingSelectedItems(): boolean { return this.option('loadItemsOnExportingSelectedItems') ?? this.getController('data')._dataSource.remoteOperations().filtering; @@ -838,12 +850,6 @@ dataGridCore.registerModule('export', { if (args.name === 'export') { args.handled = true; this._invalidate(); - - if (args.fullName === 'export.enabled') { - if (args.value && !isDefined(this.option('onExporting'))) { - errors.log('W1024'); - } - } } }, diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/export/export.ts b/packages/devextreme/testing/testcafe/tests/dataGrid/export/export.ts index c2a06f6119e9..2bca63ab77b8 100644 --- a/packages/devextreme/testing/testcafe/tests/dataGrid/export/export.ts +++ b/packages/devextreme/testing/testcafe/tests/dataGrid/export/export.ts @@ -21,17 +21,22 @@ test('Warning should be thrown in console if exporting is enabled, but onExporti }); }); -test('Warning should be thrown in console if exporting is enabled dynamically, but onExporting is not specified', async (t) => { - const dataGrid = new DataGrid(GRID_CONTAINER); - - await dataGrid.option('export.enabled', true); - - const consoleMessages = await t.getBrowserConsoleMessages(); - const isWarningExist = !!consoleMessages?.warn.find((message) => message.startsWith('W1024')); - - await t.expect(isWarningExist).ok(); -}).before(async () => { - await createWidget('dxDataGrid', { - dataSource: [], +([ + ['export', { enabled: true }], + ['export.enabled', true], +] as const).forEach(([option, value]) => { + test(`Warning should be thrown in console if exporting is enabled dynamically with '${option}' option, but onExporting is not specified`, async (t) => { + const dataGrid = new DataGrid(GRID_CONTAINER); + + await dataGrid.option(option, value); + + const consoleMessages = await t.getBrowserConsoleMessages(); + const isWarningExist = !!consoleMessages?.warn.find((message) => message.startsWith('W1024')); + + await t.expect(isWarningExist).ok(); + }).before(async () => { + await createWidget('dxDataGrid', { + dataSource: [], + }); }); });