|
|
|
@ -11,7 +11,7 @@ import { |
|
|
|
|
useRowSelect, |
|
|
|
|
useColumnOrder, |
|
|
|
|
useExpanded, |
|
|
|
|
useResizeColumns |
|
|
|
|
useResizeColumns, |
|
|
|
|
} from "react-table"; |
|
|
|
|
|
|
|
|
|
import { COLUMNS } from "./columns"; |
|
|
|
@ -24,14 +24,13 @@ import MOCK_DATA from "./MOCK_DATA.json"; |
|
|
|
|
export function SelectColumnFilter({ |
|
|
|
|
column: { filterValue, setFilter, preFilteredRows, id, render }, |
|
|
|
|
}) { |
|
|
|
|
|
|
|
|
|
const options = React.useMemo(() => { |
|
|
|
|
const options = new Set() |
|
|
|
|
preFilteredRows.forEach(row => { |
|
|
|
|
options.add(row.values[id]) |
|
|
|
|
}) |
|
|
|
|
return [...options.values()] |
|
|
|
|
}, [id, preFilteredRows]) |
|
|
|
|
const options = new Set(); |
|
|
|
|
preFilteredRows.forEach((row) => { |
|
|
|
|
options.add(row.values[id]); |
|
|
|
|
}); |
|
|
|
|
return [...options.values()]; |
|
|
|
|
}, [id, preFilteredRows]); |
|
|
|
|
|
|
|
|
|
// Render a multi-select box
|
|
|
|
|
return ( |
|
|
|
@ -42,50 +41,40 @@ export function SelectColumnFilter({ |
|
|
|
|
name={id} |
|
|
|
|
id={id} |
|
|
|
|
value={filterValue} |
|
|
|
|
onChange={e => { |
|
|
|
|
setFilter(e.target.value || undefined) |
|
|
|
|
onChange={(e) => { |
|
|
|
|
setFilter(e.target.value || undefined); |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
<option className="text-xs" value="">همه</option> |
|
|
|
|
<option className="text-xs" value=""> |
|
|
|
|
همه |
|
|
|
|
</option> |
|
|
|
|
{options.map((option, i) => ( |
|
|
|
|
<option key={i} value={option} className="text-xs"> |
|
|
|
|
{(() => { |
|
|
|
|
if (option === 1) { |
|
|
|
|
return ( |
|
|
|
|
"وضعیت عادی" |
|
|
|
|
); |
|
|
|
|
return "وضعیت عادی"; |
|
|
|
|
} else if (option === 2) { |
|
|
|
|
return ( |
|
|
|
|
"اعلان سطح هشدار" |
|
|
|
|
); |
|
|
|
|
return "اعلان سطح هشدار"; |
|
|
|
|
} else if (option === 3) { |
|
|
|
|
return ( |
|
|
|
|
"بررسی و پیگیری" |
|
|
|
|
); |
|
|
|
|
return "بررسی و پیگیری"; |
|
|
|
|
} else if (option === 4) { |
|
|
|
|
return ( |
|
|
|
|
"وضعیت بحرانی" |
|
|
|
|
); |
|
|
|
|
return "وضعیت بحرانی"; |
|
|
|
|
} else { |
|
|
|
|
return ( |
|
|
|
|
" وضعیت پایدار" |
|
|
|
|
); |
|
|
|
|
return " وضعیت پایدار"; |
|
|
|
|
} |
|
|
|
|
})()}{" "} |
|
|
|
|
|
|
|
|
|
</option> |
|
|
|
|
))} |
|
|
|
|
|
|
|
|
|
</select> |
|
|
|
|
</label> |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const BasicTable = () => { |
|
|
|
|
const columns = React.useMemo(() => COLUMNS, []); |
|
|
|
|
const data = useMemo(() => MOCK_DATA, []); |
|
|
|
|
|
|
|
|
|
// اگر بخواهیم ردیف های جدولمون یکی در میان زنگ پس زمینه اشون با هم فرق کند
|
|
|
|
|
// اگر بخواهیم ردیف های جدولمون یکی در میان زنگ پس زمینه اشون با هم فرق کند
|
|
|
|
|
const isEven = (idx) => idx % 2 === 0; |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
@ -232,7 +221,6 @@ const BasicTable = () => { |
|
|
|
|
{">>"} |
|
|
|
|
</button> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
|
{/* */} |
|
|
|
|
{/* toggle columns */} |
|
|
|
@ -257,7 +245,7 @@ const BasicTable = () => { |
|
|
|
|
> |
|
|
|
|
<thead className="" style={{ backgroundColor: "#F3F8FF" }}> |
|
|
|
|
{headerGroups.map((headerGroup) => ( |
|
|
|
|
<tr {...headerGroup.getHeaderGroupProps()} > |
|
|
|
|
<tr {...headerGroup.getHeaderGroupProps()}> |
|
|
|
|
{headerGroup.headers.map((column) => ( |
|
|
|
|
<th |
|
|
|
|
{...column.getHeaderProps(column.getSortByToggleProps())} |
|
|
|
@ -286,7 +274,9 @@ const BasicTable = () => { |
|
|
|
|
{page.map((row, idx) => { |
|
|
|
|
prepareRow(row); |
|
|
|
|
return ( |
|
|
|
|
<tr {...row.getRowProps()}
|
|
|
|
|
<React.Fragment> |
|
|
|
|
<tr |
|
|
|
|
{...row.getRowProps()} |
|
|
|
|
// className={isEven(idx) ? "bg-gray-600" : "bg-white"}
|
|
|
|
|
> |
|
|
|
|
{row.cells.map((cell) => { |
|
|
|
@ -302,6 +292,14 @@ const BasicTable = () => { |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
|
</tr> |
|
|
|
|
{row.isExpanded ? ( |
|
|
|
|
<tr> |
|
|
|
|
<td colSpan={headerGroups[0].headers.length}> |
|
|
|
|
{renderRowSubComponent({ row: row.values })} |
|
|
|
|
</td> |
|
|
|
|
</tr> |
|
|
|
|
) : null} |
|
|
|
|
</React.Fragment> |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
|
</tbody> |
|
|
|
@ -372,5 +370,13 @@ const BasicTable = () => { |
|
|
|
|
</> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function renderRowSubComponent({ row }) { |
|
|
|
|
return ( |
|
|
|
|
<div className="pl-2 pr-5 bg-blue-200"> |
|
|
|
|
نام: {row.name} |
|
|
|
|
<br /> |
|
|
|
|
<button className="bg-blue-400">ویرایش</button> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
export default BasicTable; |
|
|
|
|