mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 22:20:56 +00:00
feat(nui): Table pagination
This commit is contained in:
1 parent
1ecb93801a
commit
0e2d2b7551
4 files changed
+113
-50
No files matched your search
@@ -27,7 +27,7 @@ const App: React.FC = () => {
|
|||||||
<MotionBox
|
<MotionBox
|
||||||
animate={{ y: [100, 0] }}
|
animate={{ y: [100, 0] }}
|
||||||
width="60%"
|
width="60%"
|
||||||
height="60%"
|
height="50%"
|
||||||
backgroundColor="#191E26"
|
backgroundColor="#191E26"
|
||||||
borderRadius="1vh"
|
borderRadius="1vh"
|
||||||
color="white"
|
color="white"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const MainContent: React.FC = ({ children }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Center h="95%" alignItems="stretch">
|
<Center h="95%" alignItems="stretch">
|
||||||
<Box h="100%" w="50%" backgroundColor="#1B2129" flex="1">
|
<Box h="100%" w="50%" backgroundColor="#1B2129" flex="1" overflowY="scroll">
|
||||||
{children}
|
{children}
|
||||||
</Box>
|
</Box>
|
||||||
</Center>
|
</Center>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const LeftBar: React.FC = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p="1.2vh" fontSize="1.5vh" float="left" w="12%" height="55vh" overflowY="scroll">
|
<Box p="1.2vh" fontSize="1.5vh" float="left" w="13%" height="55vh" overflowY="scroll">
|
||||||
<VStack align="left">
|
<VStack align="left">
|
||||||
{initData.resources.map((resource, index) => (
|
{initData.resources.map((resource, index) => (
|
||||||
<Link to={resource} key={`${resource}-${index}`}>
|
<Link to={resource} key={`${resource}-${index}`}>
|
||||||
|
|||||||
+110
-47
@@ -3,9 +3,16 @@ import { useEffect, useState, useMemo } from 'react';
|
|||||||
import { fetchNui } from '../utils/fetchNui';
|
import { fetchNui } from '../utils/fetchNui';
|
||||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||||
import { debugData } from '../utils/debugData';
|
import { debugData } from '../utils/debugData';
|
||||||
import { Table, Thead, Tbody, Tr, Th, Td, chakra } from '@chakra-ui/react';
|
import { Table, Thead, Tbody, Tr, Th, Td, chakra, Flex, IconButton, Text } from '@chakra-ui/react';
|
||||||
import { TriangleDownIcon, TriangleUpIcon } from '@chakra-ui/icons';
|
import {
|
||||||
import { useTable, useSortBy, Column } from 'react-table';
|
TriangleDownIcon,
|
||||||
|
TriangleUpIcon,
|
||||||
|
ArrowLeftIcon,
|
||||||
|
ChevronLeftIcon,
|
||||||
|
ArrowRightIcon,
|
||||||
|
ChevronRightIcon,
|
||||||
|
} from '@chakra-ui/icons';
|
||||||
|
import { useTable, useSortBy, Column, usePagination } from 'react-table';
|
||||||
|
|
||||||
interface QueryData {
|
interface QueryData {
|
||||||
date: number;
|
date: number;
|
||||||
@@ -63,58 +70,114 @@ const Resource: React.FC = () => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data }, useSortBy);
|
const {
|
||||||
|
getTableProps,
|
||||||
|
getTableBodyProps,
|
||||||
|
headerGroups,
|
||||||
|
page,
|
||||||
|
canPreviousPage,
|
||||||
|
canNextPage,
|
||||||
|
pageOptions,
|
||||||
|
pageCount,
|
||||||
|
gotoPage,
|
||||||
|
nextPage,
|
||||||
|
previousPage,
|
||||||
|
state: { pageIndex },
|
||||||
|
prepareRow,
|
||||||
|
} = useTable({ columns, data, initialState: { pageSize: 12 } }, useSortBy, usePagination);
|
||||||
|
|
||||||
// Todo: pagination
|
// Todo: pagination
|
||||||
return (
|
return (
|
||||||
<Table {...getTableProps} size="sm">
|
<>
|
||||||
<Thead>
|
<Table {...getTableProps} size="sm">
|
||||||
{headerGroups.map((header): any => (
|
<Thead>
|
||||||
<Tr {...header.getHeaderGroupProps()}>
|
{headerGroups.map((header): any => (
|
||||||
{header.headers.map((column) => (
|
<Tr {...header.getHeaderGroupProps()}>
|
||||||
<Th
|
{header.headers.map((column) => (
|
||||||
{...column.getHeaderProps(column.getSortByToggleProps())}
|
<Th
|
||||||
color="white"
|
{...column.getHeaderProps(column.getSortByToggleProps())}
|
||||||
fontFamily="Poppins"
|
color="white"
|
||||||
borderBottomColor="#313C4A"
|
|
||||||
>
|
|
||||||
{column.render('Header')}
|
|
||||||
<chakra.span pl="4">
|
|
||||||
{column.isSorted ? (
|
|
||||||
column.isSortedDesc ? (
|
|
||||||
<TriangleDownIcon aria-label="sorted descending" />
|
|
||||||
) : (
|
|
||||||
<TriangleUpIcon aria-label="sorted ascending" />
|
|
||||||
)
|
|
||||||
) : null}
|
|
||||||
</chakra.span>
|
|
||||||
</Th>
|
|
||||||
))}
|
|
||||||
</Tr>
|
|
||||||
))}
|
|
||||||
</Thead>
|
|
||||||
<Tbody {...getTableBodyProps()}>
|
|
||||||
{rows.map((row) => {
|
|
||||||
prepareRow(row);
|
|
||||||
return (
|
|
||||||
<Tr {...row.getRowProps()}>
|
|
||||||
{row.cells.map((cell) => (
|
|
||||||
<Td
|
|
||||||
{...cell.getCellProps()}
|
|
||||||
fontFamily="Poppins"
|
fontFamily="Poppins"
|
||||||
wordBreak="break-word"
|
|
||||||
textOverflow="ellipsis"
|
|
||||||
overflow="hidden"
|
|
||||||
borderBottomColor="#313C4A"
|
borderBottomColor="#313C4A"
|
||||||
>
|
>
|
||||||
{cell.render('Cell')}
|
{column.render('Header')}
|
||||||
</Td>
|
<chakra.span pl="4">
|
||||||
|
{column.isSorted ? (
|
||||||
|
column.isSortedDesc ? (
|
||||||
|
<TriangleDownIcon aria-label="sorted descending" />
|
||||||
|
) : (
|
||||||
|
<TriangleUpIcon aria-label="sorted ascending" />
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</chakra.span>
|
||||||
|
</Th>
|
||||||
))}
|
))}
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
))}
|
||||||
})}
|
</Thead>
|
||||||
</Tbody>
|
<Tbody {...getTableBodyProps()}>
|
||||||
</Table>
|
{page.map((row) => {
|
||||||
|
prepareRow(row);
|
||||||
|
return (
|
||||||
|
<Tr {...row.getRowProps()}>
|
||||||
|
{row.cells.map((cell) => (
|
||||||
|
<Td
|
||||||
|
{...cell.getCellProps()}
|
||||||
|
fontFamily="Poppins"
|
||||||
|
wordBreak="break-word"
|
||||||
|
textOverflow="ellipsis"
|
||||||
|
overflow="hidden"
|
||||||
|
borderBottomColor="#313C4A"
|
||||||
|
>
|
||||||
|
{cell.render('Cell')}
|
||||||
|
</Td>
|
||||||
|
))}
|
||||||
|
</Tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Tbody>
|
||||||
|
</Table>
|
||||||
|
|
||||||
|
<Flex mt={3} justifyContent="center " alignItems="center" p="1.2vh">
|
||||||
|
<Flex>
|
||||||
|
<IconButton
|
||||||
|
icon={<ArrowLeftIcon h={3} w={3} color="black" />}
|
||||||
|
aria-label="Last page"
|
||||||
|
onClick={() => gotoPage(0)}
|
||||||
|
size="sm"
|
||||||
|
isDisabled={!canPreviousPage}
|
||||||
|
/>
|
||||||
|
<IconButton
|
||||||
|
aria-label="Previous page"
|
||||||
|
onClick={previousPage}
|
||||||
|
isDisabled={!canPreviousPage}
|
||||||
|
icon={<ChevronLeftIcon h={6} w={6} color="black" />}
|
||||||
|
size="sm"
|
||||||
|
ml={4}
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
<Text align="center" pl={4} pr={4}>
|
||||||
|
Page {pageIndex + 1} of {pageOptions.length}
|
||||||
|
</Text>
|
||||||
|
<Flex>
|
||||||
|
<IconButton
|
||||||
|
aria-label="Next page"
|
||||||
|
onClick={nextPage}
|
||||||
|
size="sm"
|
||||||
|
isDisabled={!canNextPage}
|
||||||
|
icon={<ChevronRightIcon h={6} w={6} color="black" />}
|
||||||
|
/>
|
||||||
|
<IconButton
|
||||||
|
aria-label="Last page"
|
||||||
|
onClick={() => gotoPage(pageCount - 1)}
|
||||||
|
isDisabled={!canNextPage}
|
||||||
|
icon={<ArrowRightIcon h={3} w={3} color="black" />}
|
||||||
|
size="sm"
|
||||||
|
ml={4}
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user