diff --git a/packages/pluggableWidgets/datagrid-web/CHANGELOG.md b/packages/pluggableWidgets/datagrid-web/CHANGELOG.md index f24eb6552b..0aa4c49a0d 100644 --- a/packages/pluggableWidgets/datagrid-web/CHANGELOG.md +++ b/packages/pluggableWidgets/datagrid-web/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- We have introduced show number of rows for virtual scrolling and load more pagination mode. + ## [2.28.2] - 2024-12-12 ### Fixed diff --git a/packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts b/packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts index 352979aada..4464906c37 100644 --- a/packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts +++ b/packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts @@ -83,10 +83,16 @@ export function getProperties( ]); } }); - if (values.pagination !== "buttons") { + if (values.pagination === "buttons") { + hidePropertyIn(defaultProperties, values, "showNumberOfRows"); + } else { hidePropertyIn(defaultProperties, values, "showPagingButtons"); + } + + if (values.showNumberOfRows === false) { hidePropertyIn(defaultProperties, values, "pagingPosition"); } + if (values.pagination !== "loadMore") { hidePropertyIn(defaultProperties, values, "loadMoreButtonCaption"); } diff --git a/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx b/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx index f6e47f56c4..223a6a6327 100644 --- a/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx +++ b/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx @@ -93,6 +93,8 @@ const Container = observer((props: Props): ReactElement => { return props.datasource.status === ValueStatus.Loading; }, [exportProgress, isRefreshing, props.datasource.status, props.datasource.hasMoreItems]); + const showPagingButtonsOrRows = props.pagination === "buttons" ? props.showPagingButtons : props.showNumberOfRows; + return ( { loadMoreButtonCaption={props.loadMoreButtonCaption?.value} paging={useShowPagination({ pagination: props.pagination, - showPagingButtons: props.showPagingButtons, + showPagingButtonsOrRows, totalCount: props.datasource.totalCount, - limit: props.datasource.limit + limit: props.datasource.limit, + requestTotalCount: props.datasource.requestTotalCount })} pagingPosition={props.pagingPosition} showPagingButtons={props.showPagingButtons} diff --git a/packages/pluggableWidgets/datagrid-web/src/Datagrid.xml b/packages/pluggableWidgets/datagrid-web/src/Datagrid.xml index a955ee3ec0..0e0b440637 100644 --- a/packages/pluggableWidgets/datagrid-web/src/Datagrid.xml +++ b/packages/pluggableWidgets/datagrid-web/src/Datagrid.xml @@ -236,15 +236,6 @@ Load more - - Position of paging buttons - - - Below grid - Above grid - Both - - Show paging buttons @@ -253,6 +244,19 @@ Auto + + Show number of rows + + + + Position of pagination + + + Below grid + Above grid + Both + + Load more caption diff --git a/packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx b/packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx index cac6468179..3a99843e20 100644 --- a/packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx +++ b/packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx @@ -134,7 +134,7 @@ const Main = observer((props: WidgetProps): ReactElemen visibleColumns } = props; - const isInfinite = !paging; + const isInfinite = paginationType === "virtualScrolling"; const showHeader = !!headerContent; const showTopBar = paging && (pagingPosition === "top" || pagingPosition === "both"); @@ -149,6 +149,7 @@ const Main = observer((props: WidgetProps): ReactElemen pageSize={pageSize} showPagingButtons={props.showPagingButtons} previousPage={() => setPage && setPage(prev => prev - 1)} + pagination={paginationType} /> ) : null; diff --git a/packages/pluggableWidgets/datagrid-web/src/utils/useShowPagination.ts b/packages/pluggableWidgets/datagrid-web/src/utils/useShowPagination.ts index 349845c557..0a18ada31e 100644 --- a/packages/pluggableWidgets/datagrid-web/src/utils/useShowPagination.ts +++ b/packages/pluggableWidgets/datagrid-web/src/utils/useShowPagination.ts @@ -1,20 +1,28 @@ -import { useMemo } from "react"; +import { useMemo, useEffect } from "react"; import { PaginationEnum, ShowPagingButtonsEnum } from "../../typings/DatagridProps"; interface ShowPaginationProps { pagination: PaginationEnum; - showPagingButtons: ShowPagingButtonsEnum; + showPagingButtonsOrRows: ShowPagingButtonsEnum | boolean; totalCount?: number; limit: number; + requestTotalCount: (needTotalCount: boolean) => void; } export const useShowPagination = (props: ShowPaginationProps): boolean => { - const { pagination, showPagingButtons, totalCount, limit } = props; + const { pagination, showPagingButtonsOrRows, totalCount, limit, requestTotalCount } = props; + + useEffect(() => { + if (pagination !== "buttons" && showPagingButtonsOrRows) { + requestTotalCount(true); + } + }, [pagination]); + return useMemo(() => { return ( - pagination === "buttons" && - (showPagingButtons === "always" || - (showPagingButtons === "auto" && (totalCount ? totalCount > limit : false))) + showPagingButtonsOrRows === true || + showPagingButtonsOrRows === "always" || + (showPagingButtonsOrRows === "auto" && (totalCount ? totalCount > limit : false)) ); - }, [pagination, showPagingButtons, totalCount, limit]); + }, [pagination, showPagingButtonsOrRows, totalCount, limit]); }; diff --git a/packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts b/packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts index f479524f3b..52ce234003 100644 --- a/packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts +++ b/packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts @@ -53,10 +53,10 @@ export interface ColumnsType { export type PaginationEnum = "buttons" | "virtualScrolling" | "loadMore"; -export type PagingPositionEnum = "bottom" | "top" | "both"; - export type ShowPagingButtonsEnum = "always" | "auto"; +export type PagingPositionEnum = "bottom" | "top" | "both"; + export type ShowEmptyPlaceholderEnum = "none" | "custom"; export type OnClickTriggerEnum = "single" | "double"; @@ -116,8 +116,9 @@ export interface DatagridContainerProps { columnsFilterable: boolean; pageSize: number; pagination: PaginationEnum; - pagingPosition: PagingPositionEnum; showPagingButtons: ShowPagingButtonsEnum; + showNumberOfRows: boolean; + pagingPosition: PagingPositionEnum; loadMoreButtonCaption?: DynamicValue; showEmptyPlaceholder: ShowEmptyPlaceholderEnum; emptyPlaceholder?: ReactNode; @@ -161,8 +162,9 @@ export interface DatagridPreviewProps { columnsFilterable: boolean; pageSize: number | null; pagination: PaginationEnum; - pagingPosition: PagingPositionEnum; showPagingButtons: ShowPagingButtonsEnum; + showNumberOfRows: boolean; + pagingPosition: PagingPositionEnum; loadMoreButtonCaption: string; showEmptyPlaceholder: ShowEmptyPlaceholderEnum; emptyPlaceholder: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> }; diff --git a/packages/shared/widget-plugin-grid/src/components/Pagination.tsx b/packages/shared/widget-plugin-grid/src/components/Pagination.tsx index afb4a43b1f..cef592e119 100644 --- a/packages/shared/widget-plugin-grid/src/components/Pagination.tsx +++ b/packages/shared/widget-plugin-grid/src/components/Pagination.tsx @@ -1,6 +1,10 @@ -import { createElement, Dispatch, HTMLAttributes, ReactElement, SetStateAction } from "react"; +import { createElement, Dispatch, HTMLAttributes, ReactElement, SetStateAction, Fragment } from "react"; import ControlIcon from "../internal/ControlIcon.js"; +// copied from DatagridProps.d.ts +type PaginationEnum = "buttons" | "virtualScrolling" | "loadMore"; +type ShowPagingButtonsEnum = "always" | "auto" | "hide"; + export interface PaginationProps { canNextPage: boolean; canPreviousPage: boolean; @@ -11,13 +15,14 @@ export interface PaginationProps { pageSize: number; previousPage: () => void; setPaginationIndex?: Dispatch>; - showPagingButtons?: "always" | "auto"; + showPagingButtons?: ShowPagingButtonsEnum; labelNextPage?: string; labelPreviousPage?: string; labelFirstPage?: string; labelLastPage?: string; labelPagination?: string; labelPagingStatus?: string; + pagination: PaginationEnum; } export function Pagination(props: PaginationProps): ReactElement | null { @@ -25,9 +30,13 @@ export function Pagination(props: PaginationProps): ReactElement | null { props.numberOfItems !== undefined ? Math.ceil(props.numberOfItems / props.pageSize) : undefined; const lastPage = numberOfPages !== undefined ? numberOfPages - 1 : 0; const hasLastPage = numberOfPages !== undefined; - const initialItem = props.numberOfItems === 0 ? 0 : props.page * props.pageSize + 1; - const lastItem = getLastItem(props.canNextPage, props.numberOfItems, props.page, props.pageSize); - + const showControls = props.pagination === "buttons"; + const initialItem = props.numberOfItems === 0 ? 0 : showControls ? props.page * props.pageSize + 1 : 1; + const lastItem = showControls + ? getLastItem(props.canNextPage, props.numberOfItems ?? 0, props.page, props.pageSize) + : props.page * props.pageSize > (props.numberOfItems ?? 0) + ? props.numberOfItems ?? 0 + : props.page * props.pageSize; const setPageIndex = (page: number): void => { if (props.setPaginationIndex) { props.setPaginationIndex(page); @@ -38,63 +47,71 @@ export function Pagination(props: PaginationProps): ReactElement | null { return null; } - const pagingStatus = `${initialItem} to ${lastItem} ${ + const pagingStatus = `${showControls ? `${initialItem} to ${lastItem}` : lastItem} ${ hasLastPage ? `of ${props.numberOfItems ?? (numberOfPages ?? 1) * props.pageSize}` : "" }`; return (
- - + {showControls && ( + + + + + )} {props.labelPagingStatus ?? "Currently showing"} {pagingStatus}
{pagingStatus}
- - {hasLastPage && ( - + {showControls && ( + + + {hasLastPage && ( + + )} + )}
);