parent
0203362697
commit
8fd968cd1f
6 changed files with 364 additions and 9 deletions
@ -0,0 +1,19 @@ |
||||
import React from 'react'; |
||||
|
||||
export const ColumnFilter = ({ column }) => { |
||||
|
||||
const { filterValue, setFilter } = column
|
||||
|
||||
return ( |
||||
|
||||
<span> |
||||
|
||||
Search: {''} |
||||
|
||||
<input value={filterValue || '' } |
||||
onChange={(e) => setFilter(e.target.value)} /> |
||||
|
||||
</span> |
||||
|
||||
); |
||||
}; |
@ -0,0 +1,107 @@ |
||||
// not using
|
||||
|
||||
import React, {useMemo} from 'react'; |
||||
|
||||
import {useTable, useSortBy, useGlobalFilter, useFilters} from 'react-table'; |
||||
|
||||
import {COLUMNS} from './columns'; |
||||
|
||||
import {GlobalFilter} from './GlobalFilter'; |
||||
|
||||
import MOCK_DATA from './MOCK_DATA.json'; |
||||
|
||||
const PaginationTable = () => { |
||||
|
||||
|
||||
const columns = React.useMemo(() => COLUMNS, []) |
||||
const data = useMemo(() => MOCK_DATA,[]) |
||||
|
||||
const { |
||||
getTableProps, |
||||
getTableBodyProps, |
||||
headerGroups, |
||||
footerGroups, |
||||
rows, |
||||
prepareRow, |
||||
state, |
||||
setGlobalFilter, |
||||
} = useTable({ |
||||
columns, |
||||
data, |
||||
}, |
||||
useFilters, |
||||
useGlobalFilter, |
||||
useSortBy, |
||||
) |
||||
|
||||
|
||||
const { globalFilter } = state |
||||
|
||||
return ( |
||||
|
||||
<> |
||||
|
||||
<GlobalFilter filter={globalFilter} setFilter={setGlobalFilter} /> |
||||
|
||||
<table {...getTableProps()} className="min-w-full divide-y divide-gray-200"> |
||||
|
||||
<thead className="bg-gray-300"> |
||||
{headerGroups.map((headerGroup) => ( |
||||
<tr {...headerGroup.getHeaderGroupProps()}> |
||||
{headerGroup.headers.map((column) => ( |
||||
<th {...column.getHeaderProps(column.getSortByToggleProps())} scope="col" className="cursor-pointer px-4 py-2 text-right text-xs" style={{color: '#3287B9'}}> |
||||
{column.render('Header')} |
||||
<span> |
||||
{column.isSorted ? (column.isSortedDesc ? ' 🔽' : ' 🔼') : ''} |
||||
</span> |
||||
{/* <div> |
||||
{column.canFilter ? column.render('Filter') : null } |
||||
</div> */} |
||||
</th> |
||||
))} |
||||
</tr> |
||||
))}
|
||||
</thead> |
||||
|
||||
<tbody {...getTableBodyProps()} className="bg-white divide-y divide-gray-200"> |
||||
{rows.map((row) => { |
||||
prepareRow(row) |
||||
return( |
||||
<tr {...row.getRowProps()}> |
||||
{row.cells.map((cell) => { |
||||
return <td {...cell.getCellProps()} className="px-4 py-4 whitespace-nowrap text-sm" role="cell" style={{color:'#00253A'}}> |
||||
{cell.render('Cell')} |
||||
</td> |
||||
})} |
||||
</tr> |
||||
) |
||||
})} |
||||
</tbody> |
||||
|
||||
<tfoot className={`bg-gray-300 ${headerGroup.headers.length > 2 ? 'hidden' : 'block'}`} > |
||||
{ |
||||
footerGroups.map(footerGroup => ( |
||||
<tr {...footerGroup.getFooterGroupProps()}> |
||||
{ |
||||
footerGroup.headers.map(column => ( |
||||
<td {...column.getFooterProps} className="px-4 py-2 text-right text-xs" style={{color: '#3287B9'}}> |
||||
{ |
||||
column.render('Footer') |
||||
} |
||||
</td> |
||||
)) |
||||
} |
||||
</tr> |
||||
)) |
||||
} |
||||
</tfoot> |
||||
|
||||
</table> |
||||
|
||||
</> |
||||
|
||||
) |
||||
|
||||
}; |
||||
|
||||
export default PaginationTable; |
Loading…
Reference in new issue