|
|
@ -11,7 +11,7 @@ import { |
|
|
|
useRowSelect, |
|
|
|
useRowSelect, |
|
|
|
useColumnOrder, |
|
|
|
useColumnOrder, |
|
|
|
useExpanded, |
|
|
|
useExpanded, |
|
|
|
useResizeColumns |
|
|
|
useResizeColumns, |
|
|
|
} from "react-table"; |
|
|
|
} from "react-table"; |
|
|
|
|
|
|
|
|
|
|
|
import { COLUMNS } from "./columns"; |
|
|
|
import { COLUMNS } from "./columns"; |
|
|
@ -24,14 +24,13 @@ import MOCK_DATA from "./MOCK_DATA.json"; |
|
|
|
export function SelectColumnFilter({ |
|
|
|
export function SelectColumnFilter({ |
|
|
|
column: { filterValue, setFilter, preFilteredRows, id, render }, |
|
|
|
column: { filterValue, setFilter, preFilteredRows, id, render }, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
|
|
|
|
|
|
|
|
const options = React.useMemo(() => { |
|
|
|
const options = React.useMemo(() => { |
|
|
|
const options = new Set() |
|
|
|
const options = new Set(); |
|
|
|
preFilteredRows.forEach(row => { |
|
|
|
preFilteredRows.forEach((row) => { |
|
|
|
options.add(row.values[id]) |
|
|
|
options.add(row.values[id]); |
|
|
|
}) |
|
|
|
}); |
|
|
|
return [...options.values()] |
|
|
|
return [...options.values()]; |
|
|
|
}, [id, preFilteredRows]) |
|
|
|
}, [id, preFilteredRows]); |
|
|
|
|
|
|
|
|
|
|
|
// Render a multi-select box
|
|
|
|
// Render a multi-select box
|
|
|
|
return ( |
|
|
|
return ( |
|
|
@ -42,50 +41,40 @@ export function SelectColumnFilter({ |
|
|
|
name={id} |
|
|
|
name={id} |
|
|
|
id={id} |
|
|
|
id={id} |
|
|
|
value={filterValue} |
|
|
|
value={filterValue} |
|
|
|
onChange={e => { |
|
|
|
onChange={(e) => { |
|
|
|
setFilter(e.target.value || undefined) |
|
|
|
setFilter(e.target.value || undefined); |
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
> |
|
|
|
<option className="text-xs" value="">همه</option> |
|
|
|
<option className="text-xs" value=""> |
|
|
|
|
|
|
|
همه |
|
|
|
|
|
|
|
</option> |
|
|
|
{options.map((option, i) => ( |
|
|
|
{options.map((option, i) => ( |
|
|
|
<option key={i} value={option} className="text-xs"> |
|
|
|
<option key={i} value={option} className="text-xs"> |
|
|
|
{(() => { |
|
|
|
{(() => { |
|
|
|
if (option === 1) { |
|
|
|
if (option === 1) { |
|
|
|
return ( |
|
|
|
return "وضعیت عادی"; |
|
|
|
"وضعیت عادی" |
|
|
|
} else if (option === 2) { |
|
|
|
); |
|
|
|
return "اعلان سطح هشدار"; |
|
|
|
} else if (option === 2) { |
|
|
|
} else if (option === 3) { |
|
|
|
return ( |
|
|
|
return "بررسی و پیگیری"; |
|
|
|
"اعلان سطح هشدار" |
|
|
|
} else if (option === 4) { |
|
|
|
); |
|
|
|
return "وضعیت بحرانی"; |
|
|
|
} else if (option === 3) { |
|
|
|
} else { |
|
|
|
return ( |
|
|
|
return " وضعیت پایدار"; |
|
|
|
"بررسی و پیگیری" |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
} else if (option === 4) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
"وضعیت بحرانی" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
" وضعیت پایدار" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
})()}{" "} |
|
|
|
})()}{" "} |
|
|
|
|
|
|
|
|
|
|
|
</option> |
|
|
|
</option> |
|
|
|
))} |
|
|
|
))} |
|
|
|
|
|
|
|
|
|
|
|
</select> |
|
|
|
</select> |
|
|
|
</label> |
|
|
|
</label> |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const BasicTable = () => { |
|
|
|
const BasicTable = () => { |
|
|
|
const columns = React.useMemo(() => COLUMNS, []); |
|
|
|
const columns = React.useMemo(() => COLUMNS, []); |
|
|
|
const data = useMemo(() => MOCK_DATA, []); |
|
|
|
const data = useMemo(() => MOCK_DATA, []); |
|
|
|
|
|
|
|
|
|
|
|
// اگر بخواهیم ردیف های جدولمون یکی در میان زنگ پس زمینه اشون با هم فرق کند
|
|
|
|
// اگر بخواهیم ردیف های جدولمون یکی در میان زنگ پس زمینه اشون با هم فرق کند
|
|
|
|
const isEven = (idx) => idx % 2 === 0; |
|
|
|
const isEven = (idx) => idx % 2 === 0; |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
@ -159,7 +148,7 @@ const BasicTable = () => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
<div className="customeClass1"> |
|
|
|
<div className="customeClass1"> |
|
|
|
{headerGroups.map((headerGroup) => |
|
|
|
{headerGroups.map((headerGroup) => |
|
|
|
headerGroup.headers.map((column) => |
|
|
|
headerGroup.headers.map((column) => |
|
|
|
column.Filter ? ( |
|
|
|
column.Filter ? ( |
|
|
|
<div className="mt-2 sm:mt-0 customeClass2" key={column.id}> |
|
|
|
<div className="mt-2 sm:mt-0 customeClass2" key={column.id}> |
|
|
@ -170,10 +159,10 @@ const BasicTable = () => { |
|
|
|
)} |
|
|
|
)} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="flex flex-row items-center justify-end mb-3 mx-4"> |
|
|
|
<div className="flex flex-row items-center justify-end mb-3 mx-4"> |
|
|
|
{/* search box */} |
|
|
|
{/* search box */} |
|
|
|
{/* <GlobalFilter filter={globalFilter} setFilter={setGlobalFilter} /> */} |
|
|
|
{/* <GlobalFilter filter={globalFilter} setFilter={setGlobalFilter} /> */} |
|
|
|
{/* pagination */} |
|
|
|
{/* pagination */} |
|
|
|
<div |
|
|
|
<div |
|
|
|
className="border border-blue-400 rounded-sm py-1 px-2 flex flex-items-center" |
|
|
|
className="border border-blue-400 rounded-sm py-1 px-2 flex flex-items-center" |
|
|
|
style={{}} |
|
|
|
style={{}} |
|
|
|
> |
|
|
|
> |
|
|
@ -231,8 +220,7 @@ const BasicTable = () => { |
|
|
|
> |
|
|
|
> |
|
|
|
{">>"} |
|
|
|
{">>"} |
|
|
|
</button> |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{/* */} |
|
|
|
{/* */} |
|
|
|
{/* toggle columns */} |
|
|
|
{/* toggle columns */} |
|
|
@ -257,7 +245,7 @@ const BasicTable = () => { |
|
|
|
> |
|
|
|
> |
|
|
|
<thead className="" style={{ backgroundColor: "#F3F8FF" }}> |
|
|
|
<thead className="" style={{ backgroundColor: "#F3F8FF" }}> |
|
|
|
{headerGroups.map((headerGroup) => ( |
|
|
|
{headerGroups.map((headerGroup) => ( |
|
|
|
<tr {...headerGroup.getHeaderGroupProps()} > |
|
|
|
<tr {...headerGroup.getHeaderGroupProps()}> |
|
|
|
{headerGroup.headers.map((column) => ( |
|
|
|
{headerGroup.headers.map((column) => ( |
|
|
|
<th |
|
|
|
<th |
|
|
|
{...column.getHeaderProps(column.getSortByToggleProps())} |
|
|
|
{...column.getHeaderProps(column.getSortByToggleProps())} |
|
|
@ -286,22 +274,32 @@ const BasicTable = () => { |
|
|
|
{page.map((row, idx) => { |
|
|
|
{page.map((row, idx) => { |
|
|
|
prepareRow(row); |
|
|
|
prepareRow(row); |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<tr {...row.getRowProps()}
|
|
|
|
<React.Fragment> |
|
|
|
// className={isEven(idx) ? "bg-gray-600" : "bg-white"}
|
|
|
|
<tr |
|
|
|
> |
|
|
|
{...row.getRowProps()} |
|
|
|
{row.cells.map((cell) => { |
|
|
|
// className={isEven(idx) ? "bg-gray-600" : "bg-white"}
|
|
|
|
return ( |
|
|
|
> |
|
|
|
<td |
|
|
|
{row.cells.map((cell) => { |
|
|
|
{...cell.getCellProps()} |
|
|
|
return ( |
|
|
|
className="p-4 whitespace-nowrap text-xs" |
|
|
|
<td |
|
|
|
role="cell" |
|
|
|
{...cell.getCellProps()} |
|
|
|
style={{ color: "#00253A" }} |
|
|
|
className="p-4 whitespace-nowrap text-xs" |
|
|
|
> |
|
|
|
role="cell" |
|
|
|
{cell.render("Cell")} |
|
|
|
style={{ color: "#00253A" }} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{cell.render("Cell")} |
|
|
|
|
|
|
|
</td> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
})} |
|
|
|
|
|
|
|
</tr> |
|
|
|
|
|
|
|
{row.isExpanded ? ( |
|
|
|
|
|
|
|
<tr> |
|
|
|
|
|
|
|
<td colSpan={headerGroups[0].headers.length}> |
|
|
|
|
|
|
|
{renderRowSubComponent({ row: row.values })} |
|
|
|
</td> |
|
|
|
</td> |
|
|
|
); |
|
|
|
</tr> |
|
|
|
})} |
|
|
|
) : null} |
|
|
|
</tr> |
|
|
|
</React.Fragment> |
|
|
|
); |
|
|
|
); |
|
|
|
})} |
|
|
|
})} |
|
|
|
</tbody> |
|
|
|
</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; |
|
|
|
export default BasicTable; |
|
|
|