pixelize-design-library 1.1.58 → 1.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,8 +11,9 @@ type UseTableProps = {
11
11
  savePreferences?: (data: Record<string, any>) => void;
12
12
  noOfRowsPerPage?: number;
13
13
  isServerPagination: boolean;
14
+ totalRecords: number;
14
15
  };
15
- declare const useTable: ({ tableBorderColor, data, isPagination, selections, columns, onSelection, tablePreferences, savePreferences, noOfRowsPerPage, isServerPagination, }: UseTableProps) => {
16
+ declare const useTable: ({ tableBorderColor, data, isPagination, selections, columns, onSelection, tablePreferences, savePreferences, noOfRowsPerPage, isServerPagination, totalRecords, }: UseTableProps) => {
16
17
  tableData: DataObject[];
17
18
  tableContainerStyles: {
18
19
  borderRadius: string;
@@ -25,7 +25,7 @@ var useCustomTheme_1 = require("../../../Theme/useCustomTheme");
25
25
  var table_1 = require("../../../Utils/table");
26
26
  var defaultPageSize = 50;
27
27
  var useTable = function (_a) {
28
- var tableBorderColor = _a.tableBorderColor, data = _a.data, isPagination = _a.isPagination, selections = _a.selections, columns = _a.columns, onSelection = _a.onSelection, tablePreferences = _a.tablePreferences, savePreferences = _a.savePreferences, noOfRowsPerPage = _a.noOfRowsPerPage, isServerPagination = _a.isServerPagination;
28
+ var tableBorderColor = _a.tableBorderColor, data = _a.data, isPagination = _a.isPagination, selections = _a.selections, columns = _a.columns, onSelection = _a.onSelection, tablePreferences = _a.tablePreferences, savePreferences = _a.savePreferences, noOfRowsPerPage = _a.noOfRowsPerPage, isServerPagination = _a.isServerPagination, totalRecords = _a.totalRecords;
29
29
  var theme = (0, useCustomTheme_1.useCustomTheme)();
30
30
  var headerRefs = (0, react_1.useRef)([]);
31
31
  var _b = (0, react_1.useState)([]), columnWidths = _b[0], setColumnWidths = _b[1];
@@ -66,7 +66,19 @@ var useTable = function (_a) {
66
66
  var widths = headerRefs.current.map(function (ref) { return (ref === null || ref === void 0 ? void 0 : ref.offsetWidth) || 0; });
67
67
  setColumnWidths(widths);
68
68
  }, []);
69
- var pages = (0, react_1.useMemo)(function () { return (isPagination ? Math.ceil(tableData.length / rowsPerPage) : 0); }, [isPagination, rowsPerPage, tableData.length]);
69
+ var pages = (0, react_1.useMemo)(function () {
70
+ if (isServerPagination) {
71
+ return Math.ceil(totalRecords / (noOfRowsPerPage !== null && noOfRowsPerPage !== void 0 ? noOfRowsPerPage : 1));
72
+ }
73
+ return isPagination ? Math.ceil(tableData.length / rowsPerPage) : 0;
74
+ }, [
75
+ isPagination,
76
+ rowsPerPage,
77
+ tableData.length,
78
+ totalRecords,
79
+ isServerPagination,
80
+ noOfRowsPerPage,
81
+ ]);
70
82
  var startRow = (0, react_1.useMemo)(function () { return (!isPagination ? 0 : currentPage * rowsPerPage); }, [currentPage, isPagination, rowsPerPage]);
71
83
  var endRow = (0, react_1.useMemo)(function () { return (!isPagination ? tableData.length : startRow + rowsPerPage); }, [isPagination, rowsPerPage, startRow, tableData.length]);
72
84
  (0, react_1.useEffect)(function () {
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { TableProps } from "./TableProps";
3
3
  import "./Table.css";
4
- export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagination, onRowClick, selections, isActionFreeze, preferencesUrl, preferencesKey, preferencesName, preferencesPage, authToken, paginationMode, noOfRowsPerPage, totalPages, onPagination, }: TableProps): React.JSX.Element;
4
+ export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagination, onRowClick, selections, isActionFreeze, preferencesUrl, preferencesKey, preferencesName, preferencesPage, authToken, paginationMode, noOfRowsPerPage, totalRecords, onPagination, }: TableProps): React.JSX.Element;
@@ -39,9 +39,10 @@ var table_1 = require("../../Utils/table");
39
39
  var usePreferences_1 = require("../../Hooks/usePreferences");
40
40
  function Table(_a) {
41
41
  var _b, _c, _d;
42
- var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _e = _a.isCheckbox, isCheckbox = _e === void 0 ? false : _e, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _f = _a.noBorders, noBorders = _f === void 0 ? false : _f, _g = _a.isPagination, isPagination = _g === void 0 ? true : _g, onRowClick = _a.onRowClick, selections = _a.selections, _h = _a.isActionFreeze, isActionFreeze = _h === void 0 ? true : _h, _j = _a.preferencesUrl, preferencesUrl = _j === void 0 ? "https://pixelize.memron.net:5001/api/UserPreference" : _j, _k = _a.preferencesKey, preferencesKey = _k === void 0 ? "" : _k, _l = _a.preferencesName, preferencesName = _l === void 0 ? "" : _l, _m = _a.preferencesPage, preferencesPage = _m === void 0 ? "" : _m, _o = _a.authToken, authToken = _o === void 0 ? "" : _o, _p = _a.paginationMode, paginationMode = _p === void 0 ? "client" : _p, _q = _a.noOfRowsPerPage, noOfRowsPerPage = _q === void 0 ? 50 : _q, _r = _a.totalPages, totalPages = _r === void 0 ? 0 : _r, onPagination = _a.onPagination;
42
+ var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _e = _a.isCheckbox, isCheckbox = _e === void 0 ? false : _e, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _f = _a.noBorders, noBorders = _f === void 0 ? false : _f, _g = _a.isPagination, isPagination = _g === void 0 ? true : _g, onRowClick = _a.onRowClick, selections = _a.selections, _h = _a.isActionFreeze, isActionFreeze = _h === void 0 ? true : _h, _j = _a.preferencesUrl, preferencesUrl = _j === void 0 ? "https://pixelize.memron.net:5001/api/UserPreference" : _j, _k = _a.preferencesKey, preferencesKey = _k === void 0 ? "" : _k, _l = _a.preferencesName, preferencesName = _l === void 0 ? "" : _l, _m = _a.preferencesPage, preferencesPage = _m === void 0 ? "" : _m, _o = _a.authToken, authToken = _o === void 0 ? "" : _o, _p = _a.paginationMode, paginationMode = _p === void 0 ? "client" : _p, _q = _a.noOfRowsPerPage, noOfRowsPerPage = _q === void 0 ? 50 : _q, _r = _a.totalRecords, totalRecords = _r === void 0 ? 0 : _r, onPagination = _a.onPagination;
43
43
  var theme = (0, useCustomTheme_1.useCustomTheme)();
44
44
  var _s = (0, react_1.useState)({}), columnsSearch = _s[0], setColumnsSearch = _s[1];
45
+ var isServerPagination = paginationMode === "server";
45
46
  var _t = (0, usePreferences_1.useGetPreferences)({
46
47
  baseUrl: preferencesUrl,
47
48
  page: preferencesPage,
@@ -75,7 +76,8 @@ function Table(_a) {
75
76
  tablePreferences: tablePreferences,
76
77
  savePreferences: savePreferences,
77
78
  noOfRowsPerPage: noOfRowsPerPage,
78
- isServerPagination: paginationMode === "server",
79
+ totalRecords: totalRecords,
80
+ isServerPagination: isServerPagination,
79
81
  }), tableData = _u.tableData, tableContainerStyles = _u.tableContainerStyles, isContent = _u.isContent, isLink = _u.isLink, headerRefs = _u.headerRefs, columnWidths = _u.columnWidths, visibleColumns = _u.visibleColumns, handleSort = _u.handleSort, handleCheckbox = _u.handleCheckbox, filteredData = _u.filteredData, startRow = _u.startRow, endRow = _u.endRow, selection = _u.selection, columnsSort = _u.columnsSort, currentPage = _u.currentPage, pages = _u.pages, rowsPerPage = _u.rowsPerPage, handleColumnVisibilityChange = _u.handleColumnVisibilityChange, handlePageSizeChange = _u.handlePageSizeChange, setCurrentPage = _u.setCurrentPage;
80
82
  var _filteredData = (0, react_1.useMemo)(function () {
81
83
  return (0, table_1.searchAndSortData)(filteredData, columnsSearch);
@@ -96,6 +98,6 @@ function Table(_a) {
96
98
  : "indeterminate", isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze, setColumnsSearch: setColumnsSearch, columnsSearch: columnsSearch })),
97
99
  react_1.default.createElement(react_3.Tbody, null,
98
100
  react_1.default.createElement(TableBody_1.default, { data: _filteredData, columns: columns, startRow: startRow, endRow: endRow, visibleColumns: visibleColumns, isCheckbox: isCheckbox, columnWidths: columnWidths, noBorders: noBorders, freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.gray[600], handleCheckbox: handleCheckbox, selections: selection, isLoading: isTableLoading, onRowClick: onRowClick, isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze })))),
99
- isPagination && (react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: paginationMode === "server" ? totalPages : pages, paginationText: "".concat(startRow + 1, " to ").concat(endRow, " of ").concat(tableData.length), handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: paginationMode === "server", visibleColumns: visibleColumns, handleColumnVisibilityChange: handleColumnVisibilityChange, isVisiblity: true }))));
101
+ (isPagination || isServerPagination) && (react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: "".concat(startRow + 1, " to ").concat(endRow, " of ").concat(isServerPagination ? totalRecords : tableData.length), handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: isServerPagination, visibleColumns: visibleColumns, handleColumnVisibilityChange: handleColumnVisibilityChange, isVisiblity: true }))));
100
102
  }
101
103
  exports.default = Table;
@@ -26,7 +26,7 @@ export type TableProps = {
26
26
  authToken?: string;
27
27
  paginationMode?: "client" | "server";
28
28
  noOfRowsPerPage?: number;
29
- totalPages?: number;
29
+ totalRecords?: number;
30
30
  onPagination?: (page: number, noOfRecords: number) => void;
31
31
  };
32
32
  export type DataObject = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "1.1.58",
3
+ "version": "1.1.59",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",