From 85718e18cd181734df3ba1a2440ead4368741c53 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Thu, 7 Jan 2021 10:37:46 -0500 Subject: [PATCH] fix(plugins): throw error when Tree Data used with Pagination (#229) --- .../components/__tests__/slick-vanilla-grid.spec.ts | 11 +++++++++++ .../src/components/slick-vanilla-grid-bundle.ts | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts b/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts index 105abb58a..fcd557e93 100644 --- a/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts +++ b/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid.spec.ts @@ -1783,6 +1783,17 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () }); describe('Tree Data View', () => { + it('should throw an error when enableTreeData is enabled with Pagination since that is not supported', (done) => { + try { + component.gridOptions = { enableTreeData: true, enablePagination: true } as GridOption; + component.initialization(divContainer, slickEventHandler); + } catch (e) { + expect(e.toString()).toContain('[Slickgrid-Universal] It looks like you are trying to use Tree Data with Pagination but unfortunately that is simply not supported because of its complexity.'); + component.dispose(); + done(); + } + }); + it('should throw an error when enableTreeData is enabled without passing a "columnId"', (done) => { try { component.gridOptions = { enableTreeData: true, treeDataOptions: {} } as unknown as GridOption; diff --git a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts index 3c06a66e8..63d1e4c7f 100644 --- a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts +++ b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts @@ -523,6 +523,11 @@ export class SlickVanillaGridBundle { } if (this._gridOptions?.enableTreeData) { + // Tree Data with Pagiantion is not supported, throw an error when user tries to do that + if (this.gridOptions.enablePagination) { + throw new Error('[Slickgrid-Universal] It looks like you are trying to use Tree Data with Pagination but unfortunately that is simply not supported because of its complexity.'); + } + if (!this._gridOptions.treeDataOptions || !this._gridOptions.treeDataOptions.columnId) { throw new Error('[Slickgrid-Universal] When enabling tree data, you must also provide the "treeDataOption" property in your Grid Options with "childrenPropName" or "parentPropName" (depending if your array is hierarchical or flat) for the Tree Data to work properly'); }