From 408d116c44981b09c4b6c3066842cb8d70f9b11a Mon Sep 17 00:00:00 2001 From: Souma Ghosh <103924539+souma-ghosh@users.noreply.github.com> Date: Fri, 21 Oct 2022 13:14:46 +0530 Subject: [PATCH] fix: Incorrect page count when number of records in page is different from page size (#17535) --- .../TableV2/TableV2_pagination_spec.js | 22 +++++++++++++++++++ .../widgets/TableWidgetV2/component/Table.tsx | 12 ++++++++-- .../TableWidgetV2/component/TableHeader.tsx | 4 +++- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/TableV2/TableV2_pagination_spec.js diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/TableV2/TableV2_pagination_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/TableV2/TableV2_pagination_spec.js new file mode 100644 index 0000000000..82a01a6329 --- /dev/null +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/TableV2/TableV2_pagination_spec.js @@ -0,0 +1,22 @@ +const commonlocators = require("../../../../../locators/commonlocators.json"); +const dsl = require("../../../../../fixtures/tableV2NewDslWithPagination.json"); + +describe("Table Widget property pane feature validation", function() { + before(() => { + cy.addDsl(dsl); + }); + + it("1. Verify table column type changes effect on menuButton and iconButton", function() { + cy.openPropertyPane("tablewidgetv2"); + cy.CheckWidgetProperties(commonlocators.serverSidePaginationCheckbox); + cy.get(".t--property-control-totalrecords pre.CodeMirror-line span span") + .click() + .type("26"); + cy.wait(1000); + cy.get(`.t--draggable-tablewidgetv2 span[data-pagecount="20"]`).should( + "exist", + ); + + cy.closePropertyPane(); + }); +}); diff --git a/app/client/src/widgets/TableWidgetV2/component/Table.tsx b/app/client/src/widgets/TableWidgetV2/component/Table.tsx index 833671e16a..4c88bda8a3 100644 --- a/app/client/src/widgets/TableWidgetV2/component/Table.tsx +++ b/app/client/src/widgets/TableWidgetV2/component/Table.tsx @@ -137,9 +137,17 @@ export function Table(props: TableProps) { }), [columnString], ); + /* + For serverSidePaginationEnabled we are taking props.data.length as the page size. + As props.pageSize is being set by the visible number of rows in the table (without scrolling), + it will not give the correct count of records in the current page when query limit + is set higher/lower than the visible number of rows in the table + */ const pageCount = - props.serverSidePaginationEnabled && props.totalRecordsCount - ? Math.ceil(props.totalRecordsCount / props.pageSize) + props.serverSidePaginationEnabled && + props.totalRecordsCount && + props.data.length + ? Math.ceil(props.totalRecordsCount / props.data.length) : Math.ceil(props.data.length / props.pageSize); const currentPageIndex = props.pageNo < pageCount ? props.pageNo : 0; const { diff --git a/app/client/src/widgets/TableWidgetV2/component/TableHeader.tsx b/app/client/src/widgets/TableWidgetV2/component/TableHeader.tsx index 75e7a1049f..e1f4a195a4 100644 --- a/app/client/src/widgets/TableWidgetV2/component/TableHeader.tsx +++ b/app/client/src/widgets/TableWidgetV2/component/TableHeader.tsx @@ -290,7 +290,9 @@ function TableHeader(props: TableHeaderProps) { {props.pageNo + 1}   - {`of ${props.pageCount}`} + {`of ${props.pageCount}`} ) : (