fix: Incorrect page count when number of records in page is different from page size (#17535)

This commit is contained in:
Souma Ghosh 2022-10-21 13:14:46 +05:30 committed by GitHub
parent ea070517d3
commit 408d116c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View File

@ -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();
});
});

View File

@ -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 {

View File

@ -290,7 +290,9 @@ function TableHeader(props: TableHeaderProps) {
{props.pageNo + 1}
</PaginationItemWrapper>
&nbsp;
<span>{`of ${props.pageCount}`}</span>
<span
data-pagecount={props.pageCount}
>{`of ${props.pageCount}`}</span>
</TableHeaderContentWrapper>
) : (
<PaginationItemWrapper