From b21e6a65bd6168143c2c0f34dbea21ac4caced59 Mon Sep 17 00:00:00 2001 From: Joseph Ojoko Date: Fri, 29 Dec 2023 10:08:54 +0100 Subject: [PATCH] fix(DataTable): external pagination, and sticky table header (#100) --- example/cypress/e2e/data-table.cy.ts | 20 ++++++++----- example/src/assets/main.css | 6 +++- example/src/main.ts | 1 + src/components/tables/DataTable.vue | 44 ++++++++++++++++------------ src/composables/sticky-header.ts | 34 +++++++++------------ 5 files changed, 57 insertions(+), 48 deletions(-) diff --git a/example/cypress/e2e/data-table.cy.ts b/example/cypress/e2e/data-table.cy.ts index 0d6c874..987e0aa 100644 --- a/example/cypress/e2e/data-table.cy.ts +++ b/example/cypress/e2e/data-table.cy.ts @@ -197,33 +197,37 @@ describe('DataTable', () => { }); it('checks for data tables with sticky header', () => { - cy.get('div[data-cy=table-expandable-0]').as('sticky'); + cy.get('div[data-cy="table-expandable-0"]').as('sticky'); cy.get('@sticky') .find('> div > table > tbody > tr:nth-child(5)') .as('row4'); cy.get('@sticky') - .find('> div > table thead[data-id=head-clone]') + .find('> div > table > thead[data-id=head-clone]') + .should('exist'); + + cy.get('@sticky') + .find('> div > table > thead[data-id=head-main]') + .as('mainHead') .should('exist'); cy.get('@row4') .scrollIntoView() - .get('@sticky') - .find('> div > table thead[data-id=head-main]') + .get('@mainHead') .should((thead) => { const classes = Cypress.$(thead).attr('class'); expect(classes).to.contain('_sticky__header_'); - expect(classes).to.contain('_stick__top_'); + expect(classes).not.to.contain('_stick__top_'); }); cy.window() + .get('body') .scrollTo('top') - .get('@sticky') - .find('> div > table thead[data-id=head-main][class*=_sticky__header_]') + .get('@mainHead') .should((thead) => { const classes = Cypress.$(thead).attr('class'); - expect(classes).to.contain('_stick__top_'); + expect(classes).not.to.contain('_stick__top_'); }); }); }); diff --git a/example/src/assets/main.css b/example/src/assets/main.css index d750d4b..0263b16 100644 --- a/example/src/assets/main.css +++ b/example/src/assets/main.css @@ -1,8 +1,12 @@ @import './style.css'; @layer base { + html { + @apply overflow-hidden; + } + body { - @apply bg-white text-black; + @apply bg-white text-black h-screen overflow-y-auto overflow-x-hidden; } .dark body { diff --git a/example/src/main.ts b/example/src/main.ts index 895b57a..fb1f046 100644 --- a/example/src/main.ts +++ b/example/src/main.ts @@ -72,6 +72,7 @@ const RuiPlugin = createRui({ defaults: { table: { itemsPerPage, + globalItemsPerPage: false, }, }, }); diff --git a/src/components/tables/DataTable.vue b/src/components/tables/DataTable.vue index 2c9722f..61b04cc 100644 --- a/src/components/tables/DataTable.vue +++ b/src/components/tables/DataTable.vue @@ -197,10 +197,14 @@ const { expanded, singleExpand, stickyOffset, + stickyHeader, } = toRefs(props); const css = useCssModule(); -const { stick, table, tableScroller } = useStickyTableHeader(stickyOffset); +const { stick, table, tableScroller } = useStickyTableHeader( + stickyOffset, + stickyHeader, +); const tableDefaults = useTable(); const globalItemsPerPageSettings = computed(() => { if (props.globalItemsPerPage !== undefined) { @@ -287,6 +291,10 @@ const paginationData: Ref = computed({ }; } + if (get(paginationModifiers)?.external) { + return paginated; + } + return { total: get(searchData).length, limit: paginated.limit, @@ -745,11 +753,7 @@ const slots = useSlots(); { [css.thead__loader_linear]: !noData }, ]" > - +
+