parent
18f0207ba2
commit
0203362697
9 changed files with 351 additions and 52 deletions
@ -0,0 +1,99 @@ |
||||
// not using
|
||||
|
||||
import React, {useMemo} from 'react'; |
||||
import {useTable, useSortBy, useGlobalFilter} from 'react-table'; |
||||
import {COLUMNS} from './columns'; |
||||
import MOCK_DATA from './MOCK_DATA.json'; |
||||
|
||||
|
||||
const FilteringTable = () => { |
||||
|
||||
|
||||
const columns = React.useMemo(() => COLUMNS, []) |
||||
const data = useMemo(() => MOCK_DATA,[]) |
||||
|
||||
const { |
||||
getTableProps, |
||||
getTableBodyProps, |
||||
headerGroups, |
||||
footerGroups, |
||||
rows, |
||||
prepareRow, |
||||
state, |
||||
setGlobalFilter, |
||||
} = useTable({ |
||||
columns, |
||||
data, |
||||
}, |
||||
useSortBy, |
||||
useGlobalFilter |
||||
) |
||||
|
||||
|
||||
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="px-4 py-2 text-right text-xs" style={{color: '#3287B9'}}> |
||||
{column.render('Header')} |
||||
<span> |
||||
{column.isSorted ? (column.isSortedDesc ? ' 🔽' : ' 🔼') : ''} |
||||
</span> |
||||
</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"> |
||||
{ |
||||
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 FilteringTable; |
@ -0,0 +1,15 @@ |
||||
import React from 'react'; |
||||
|
||||
export const GlobalFilter = ({ filter, setFilter }) => { |
||||
return ( |
||||
|
||||
<span> |
||||
|
||||
Search: {''} |
||||
|
||||
<input value={filter || '' } onChange={(e) => setFilter(e.target.value)} /> |
||||
|
||||
</span> |
||||
|
||||
); |
||||
}; |
@ -0,0 +1,88 @@ |
||||
// not using
|
||||
|
||||
|
||||
import React, {useMemo} from 'react'; |
||||
import {useTable, useSortBy} from 'react-table'; |
||||
import {COLUMNS} from './columns'; |
||||
import MOCK_DATA from './MOCK_DATA.json'; |
||||
|
||||
|
||||
const SortingTable = () => { |
||||
|
||||
|
||||
const columns = React.useMemo(() => COLUMNS, []) |
||||
const data = useMemo(() => MOCK_DATA,[]) |
||||
|
||||
const { |
||||
getTableProps, |
||||
getTableBodyProps, |
||||
headerGroups, |
||||
footerGroups, |
||||
rows, |
||||
prepareRow, |
||||
} = useTable({ |
||||
columns, |
||||
data, |
||||
}, |
||||
useSortBy |
||||
) |
||||
|
||||
|
||||
return ( |
||||
|
||||
<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="px-4 py-2 text-right text-xs" style={{color: '#3287B9'}}> |
||||
{column.render('Header')} |
||||
<span> |
||||
{column.isSorted ? (column.isSortedDesc ? ' 🔽' : ' 🔼') : ''} |
||||
</span> |
||||
</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"> |
||||
{ |
||||
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 SortingTable; |
@ -1,37 +1,42 @@ |
||||
import {format} from 'date-fns' |
||||
|
||||
export const COLUMNS = [ |
||||
{ |
||||
Header: 'نام و نام خانوادگی', |
||||
Footer: 'نام و نام خانوادگی', |
||||
accessor: 'name', |
||||
|
||||
disableSortBy: true, |
||||
}, |
||||
{ |
||||
Header: 'تاریخ سفارش', |
||||
Footer: 'تاریخ سفارش', |
||||
accessor: 'order-date', |
||||
|
||||
Cell: ({ value }) => { return format(new Date (value), 'dd/MM/yyyy') } |
||||
}, |
||||
{ |
||||
Header: 'مبلغ سفارش', |
||||
Footer: 'مبلغ سفارش', |
||||
accessor: 'order-price', |
||||
|
||||
}, |
||||
{ |
||||
Header: 'شماره سفارش', |
||||
Footer: 'شماره سفارش', |
||||
accessor: 'order-number', |
||||
|
||||
}, |
||||
{ |
||||
Header: 'شغل کاربر', |
||||
Footer: 'شغل کاربر', |
||||
accessor: 'user-job', |
||||
|
||||
}, |
||||
{ |
||||
Header: 'وضعیت سفارش', |
||||
Footer: 'وضعیت سفارش', |
||||
accessor: 'order-status', |
||||
|
||||
}, |
||||
{ |
||||
Header: 'سطح اهمیت', |
||||
Footer: 'سطح اهمیت', |
||||
accessor: 'order-level', |
||||
|
||||
disableSortBy: true, |
||||
}, |
||||
] |
Loading…
Reference in new issue