2
0
Эх сурвалжийг харах

adjust grid row count calculation (#403)

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 жил өмнө
parent
commit
89092e1881

+ 8 - 11
client/src/components/grid/Grid.tsx

@@ -103,7 +103,7 @@ const AttuGrid: FC<AttuGridType> = props => {
     rowCount = 20,
     rowCount = 20,
     rowsPerPage = 10,
     rowsPerPage = 10,
     tableHeaderHeight = 46,
     tableHeaderHeight = 46,
-    rowHeight = 49,
+    rowHeight = 43,
     pagerHeight = 52,
     pagerHeight = 52,
     primaryKey = 'id',
     primaryKey = 'id',
     showToolbar = false,
     showToolbar = false,
@@ -181,17 +181,14 @@ const AttuGrid: FC<AttuGridType> = props => {
   const calculateRowCountAndPageSize = () => {
   const calculateRowCountAndPageSize = () => {
     if (tableRef.current && rowHeight > 0) {
     if (tableRef.current && rowHeight > 0) {
       const containerHeight: number = tableRef.current.offsetHeight;
       const containerHeight: number = tableRef.current.offsetHeight;
+      const hasToolbar = toolbarConfigs.length > 0;
+      const totleHeight =
+        containerHeight -
+        tableHeaderHeight -
+        (showPagination ? pagerHeight : 0) -
+        (hasToolbar ? 34 : 0);
 
 
-      const rowCount = Math.floor(
-        (containerHeight -
-          tableHeaderHeight -
-          (showPagination ? pagerHeight : 0)) /
-          rowHeight
-      );
-
-      // console.log('calc', tableRef.current.offsetHeight);
-      // console.log(rowCount, containerHeight, tableHeaderHeight);
-      setLoadingRowCount(rowCount);
+      const rowCount = Math.floor(totleHeight / rowHeight);
 
 
       if (setRowsPerPage) {
       if (setRowsPerPage) {
         setRowsPerPage(rowCount);
         setRowsPerPage(rowCount);

+ 1 - 1
client/src/components/grid/Table.tsx

@@ -46,7 +46,7 @@ const useStyles = makeStyles(theme => ({
   },
   },
   tableCell: {
   tableCell: {
     background: theme.palette.common.white,
     background: theme.palette.common.white,
-    padding: `${theme.spacing(1.5)} `,
+    padding: theme.spacing(1, 1.5),
   },
   },
   cellContainer: {
   cellContainer: {
     display: 'flex',
     display: 'flex',

+ 1 - 0
client/src/pages/collections/Collections.tsx

@@ -646,6 +646,7 @@ const Collections = () => {
           page={currentPage}
           page={currentPage}
           onPageChange={handlePageChange}
           onPageChange={handlePageChange}
           rowsPerPage={pageSize}
           rowsPerPage={pageSize}
+          rowHeight={49}
           setRowsPerPage={handlePageSize}
           setRowsPerPage={handlePageSize}
           isLoading={loading}
           isLoading={loading}
           handleSort={handleGridSort}
           handleSort={handleGridSort}

+ 1 - 0
client/src/pages/query/Query.tsx

@@ -390,6 +390,7 @@ const Query = () => {
         isLoading={!!tableLoading}
         isLoading={!!tableLoading}
         rows={queryResult.data}
         rows={queryResult.data}
         rowCount={total}
         rowCount={total}
+        rowHeight={43}
         selected={selectedData}
         selected={selectedData}
         setSelected={onSelectChange}
         setSelected={onSelectChange}
         page={currentPage}
         page={currentPage}