From ea2c1759fa78c47411ba65fda5a8d619d0d8f7e3 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Wed, 19 Jun 2024 00:37:50 -0400 Subject: [PATCH] feat: add onPreHeaderContextMenu for Column Picker usage (#1030) * feat: add onPreHeaderContextMenu for Column Picker usage - adding new events `onPreHeaderContextMenu` and `onPreHeaderClick` which is mostly to be able to open the Column Picker from either the regular column headers OR the Column Group from the Pre-Header when defined --- .../example-draggable-header-grouping.cy.ts | 37 +++ ...mple-frozen-columns-and-column-group.cy.ts | 238 ++++++++++-------- examples/example-column-group.html | 72 +++--- .../example-draggable-header-grouping.html | 62 +++-- ...n-columns-and-column-group-hidden-col.html | 62 ++--- ...ample-frozen-columns-and-column-group.html | 65 +++-- src/controls/slick.columnpicker.ts | 8 +- src/models/gridEvents.interface.ts | 2 + src/slick.core.ts | 6 +- src/slick.grid.ts | 34 ++- 10 files changed, 368 insertions(+), 218 deletions(-) diff --git a/cypress/e2e/example-draggable-header-grouping.cy.ts b/cypress/e2e/example-draggable-header-grouping.cy.ts index 5ec925a0d..691c867dd 100644 --- a/cypress/e2e/example-draggable-header-grouping.cy.ts +++ b/cypress/e2e/example-draggable-header-grouping.cy.ts @@ -214,5 +214,42 @@ describe('Example - Draggable Grouping', { retries: 1 }, () => { // cy.get(`#myGrid [style="top: ${GRID_ROW_HEIGHT * 49999}px;"] > .slick-cell:nth(1)`).should('have.text', 'Task 49999'); cy.get(`#myGrid [style="top: 1.24998e+06px;"] > .slick-cell:nth(1)`).should('have.text', 'Task 49999'); }); + + it('should be able to call column picker from the pre-header', () => { + const preHeadersWithoutId = ['Common Factor', 'Period', 'Analysis', '']; + const titlesWithoutId = ['Title', 'Duration', 'Start', 'Finish', 'Cost', 'Effort-Driven']; + + cy.get('#myGrid') + .find('.slick-preheader-panel .slick-header-column:nth(1)') + .trigger('mouseover') + .trigger('contextmenu') + .invoke('show'); + + cy.get('.slick-columnpicker') + .find('.slick-columnpicker-list') + .children() + .each(($child, index) => { + if (index <= 5) { + expect($child.text()).to.eq(fullTitles[index]); + } + }); + + cy.get('.slick-columnpicker') + .find('.slick-columnpicker-list') + .children('li:nth-child(1)') + .children('label') + .should('contain', '#') + .click(); + + cy.get('#myGrid') + .find('.slick-preheader-panel .slick-header-columns') + .children() + .each(($child, index) => expect($child.text()).to.eq(preHeadersWithoutId[index])); + + cy.get('#myGrid') + .find('.slick-header:not(.slick-preheader-panel) .slick-header-columns') + .children() + .each(($child, index) => expect($child.text()).to.eq(titlesWithoutId[index])); + }); }); }); diff --git a/cypress/e2e/example-frozen-columns-and-column-group.cy.ts b/cypress/e2e/example-frozen-columns-and-column-group.cy.ts index 5ebef9c4a..986ff5e80 100644 --- a/cypress/e2e/example-frozen-columns-and-column-group.cy.ts +++ b/cypress/e2e/example-frozen-columns-and-column-group.cy.ts @@ -1,101 +1,141 @@ describe('Example - Row Grouping Titles', () => { - const fullPreTitles = ['', 'Common Factor', 'Period', 'Analysis']; - const fullTitles = ['#', 'Title', 'Duration', 'Start', 'Finish', '% Complete', 'Effort Driven']; - - it('should display Example Frozen Columns & Column Group', () => { - cy.visit(`${Cypress.config('baseUrl')}/examples/example-frozen-columns-and-column-group.html`); - cy.get('h2').should('contain', 'Demonstrates:'); - cy.contains('Frozen columns with extra header row grouping columns into categories'); - }); - - it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { - cy.get('#myGrid') - .find('.slick-header-columns:nth(0)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); - - cy.get('#myGrid') - .find('.slick-header-columns:nth(1)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); - }); - - it('should have a frozen grid on page load with 3 columns on the left and 4 columns on the right', () => { - cy.get('[style="top: 0px;"]').should('have.length', 2); - cy.get('.grid-canvas-left > [style="top: 0px;"]').children().should('have.length', 3); - cy.get('.grid-canvas-right > [style="top: 0px;"]').children().should('have.length', 4); - - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '0'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', 'Task 0'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(2)').should('contain', '5 days'); - - cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '01/01/2009'); - cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', '01/05/2009'); - }); - - it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { - cy.get('#myGrid') - .find('.slick-header-columns:nth(0)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); - - cy.get('#myGrid') - .find('.slick-header-columns:nth(1)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); - }); - - it('should click on the "Remove Frozen Columns" button to switch to a regular grid without frozen columns and expect 7 columns on the left container', () => { - cy.contains('Remove Frozen Columns') - .click({ force: true }); - - cy.get('[style="top: 0px;"]').should('have.length', 1); - cy.get('.grid-canvas-left > [style="top: 0px;"]').children().should('have.length', 7); - - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '0'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', 'Task 0'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(2)').should('contain', '5 days'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(3)').should('contain', '01/01/2009'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(4)').should('contain', '01/05/2009'); - }); - - it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { - cy.get('#myGrid') - .find('.slick-header-columns:nth(0)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); - - cy.get('#myGrid') - .find('.slick-header-columns:nth(1)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); - }); - - it('should click on the "Set 3 Frozen Columns" button to switch frozen columns grid and expect 3 frozen columns on the left and 4 columns on the right', () => { - cy.contains('Set 3 Frozen Columns') - .click({ force: true }); - - cy.get('[style="top: 0px;"]').should('have.length', 2); - cy.get('.grid-canvas-left > [style="top: 0px;"]').children().should('have.length', 3); - cy.get('.grid-canvas-right > [style="top: 0px;"]').children().should('have.length', 4); - - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '0'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', 'Task 0'); - cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(2)').should('contain', '5 days'); - - cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '01/01/2009'); - cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', '01/05/2009'); - }); - - it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { - cy.get('#myGrid') - .find('.slick-header-columns:nth(0)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); - - cy.get('#myGrid') - .find('.slick-header-columns:nth(1)') - .children() - .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); - }); + const fullPreTitles = ['', 'Common Factor', 'Period', 'Analysis']; + const fullTitles = ['#', 'Title', 'Duration', 'Start', 'Finish', '% Complete', 'Effort Driven']; + + it('should display Example Frozen Columns & Column Group', () => { + cy.visit(`${Cypress.config('baseUrl')}/examples/example-frozen-columns-and-column-group.html`); + cy.get('h2').should('contain', 'Demonstrates:'); + cy.contains('Frozen columns with extra header row grouping columns into categories'); + }); + + it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { + cy.get('#myGrid') + .find('.slick-header-columns:nth(0)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); + + cy.get('#myGrid') + .find('.slick-header-columns:nth(1)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); + }); + + it('should have a frozen grid on page load with 3 columns on the left and 4 columns on the right', () => { + cy.get('[style="top: 0px;"]').should('have.length', 2); + cy.get('.grid-canvas-left > [style="top: 0px;"]').children().should('have.length', 3); + cy.get('.grid-canvas-right > [style="top: 0px;"]').children().should('have.length', 4); + + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '0'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', 'Task 0'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(2)').should('contain', '5 days'); + + cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '01/01/2009'); + cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', '01/05/2009'); + }); + + it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { + cy.get('#myGrid') + .find('.slick-header-columns:nth(0)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); + + cy.get('#myGrid') + .find('.slick-header-columns:nth(1)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); + }); + + it('should click on the "Remove Frozen Columns" button to switch to a regular grid without frozen columns and expect 7 columns on the left container', () => { + cy.contains('Remove Frozen Columns') + .click({ force: true }); + + cy.get('[style="top: 0px;"]').should('have.length', 1); + cy.get('.grid-canvas-left > [style="top: 0px;"]').children().should('have.length', 7); + + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '0'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', 'Task 0'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(2)').should('contain', '5 days'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(3)').should('contain', '01/01/2009'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(4)').should('contain', '01/05/2009'); + }); + + it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { + cy.get('#myGrid') + .find('.slick-header-columns:nth(0)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); + + cy.get('#myGrid') + .find('.slick-header-columns:nth(1)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); + }); + + it('should click on the "Set 3 Frozen Columns" button to switch frozen columns grid and expect 3 frozen columns on the left and 4 columns on the right', () => { + cy.contains('Set 3 Frozen Columns') + .click({ force: true }); + + cy.get('[style="top: 0px;"]').should('have.length', 2); + cy.get('.grid-canvas-left > [style="top: 0px;"]').children().should('have.length', 3); + cy.get('.grid-canvas-right > [style="top: 0px;"]').children().should('have.length', 4); + + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '0'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', 'Task 0'); + cy.get('.grid-canvas-left > [style="top: 0px;"] > .slick-cell:nth(2)').should('contain', '5 days'); + + cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(0)').should('contain', '01/01/2009'); + cy.get('.grid-canvas-right > [style="top: 0px;"] > .slick-cell:nth(1)').should('contain', '01/05/2009'); + }); + + it('should have exact Column Pre-Header & Column Header Titles in the grid', () => { + cy.get('#myGrid') + .find('.slick-header-columns:nth(0)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullPreTitles[index])); + + cy.get('#myGrid') + .find('.slick-header-columns:nth(1)') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullTitles[index])); + }); + + it('should be able to call column picker from the pre-header', () => { + const fullPreTitlesWithoutId = ['Common Factor', 'Period', 'Period', 'Analysis']; + const fullTitlesWithoutId = ['Title', 'Duration', 'Start', 'Finish', '% Complete', 'Effort Driven']; + const fullTitlesWithGroup = ['#', 'Common Factor - Title', 'Common Factor - Duration', 'Period - Start', 'Period - Finish', 'Analysis - % Complete', 'Analysis - Effort Driven']; + + cy.get('#myGrid') + .find('.slick-preheader-panel .slick-header-column:nth(1)') + .trigger('mouseover') + .trigger('contextmenu') + .invoke('show'); + + cy.get('.slick-columnpicker') + .find('.slick-columnpicker-list') + .children() + .each(($child, index) => { + if (index <= 6) { + expect($child.text()).to.eq(fullTitlesWithGroup[index]); + } + }); + + cy.get('.slick-columnpicker') + .find('.slick-columnpicker-list') + .children('li:nth-child(1)') + .children('label') + .should('contain', '#') + .click(); + + cy.get('.slick-columnpicker > button.close > .close').click(); + + cy.get('#myGrid') + .find('.slick-preheader-panel .slick-header-columns') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullPreTitlesWithoutId[index])); + + cy.get('#myGrid') + .find('.slick-header:not(.slick-preheader-panel) .slick-header-columns') + .children() + .each(($child, index) => expect($child.text()).to.eq(fullTitlesWithoutId[index])); + }); }); diff --git a/examples/example-column-group.html b/examples/example-column-group.html index 21dff43c4..8e4561dc6 100644 --- a/examples/example-column-group.html +++ b/examples/example-column-group.html @@ -49,41 +49,45 @@

View Source: