|
|
@ -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,43 +41,33 @@ 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) { |
|
|
|
} else if (option === 2) { |
|
|
|
return ( |
|
|
|
return "اعلان سطح هشدار"; |
|
|
|
"اعلان سطح هشدار" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else if (option === 3) { |
|
|
|
} else if (option === 3) { |
|
|
|
return ( |
|
|
|
return "بررسی و پیگیری"; |
|
|
|
"بررسی و پیگیری" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else if (option === 4) { |
|
|
|
} else if (option === 4) { |
|
|
|
return ( |
|
|
|
return "وضعیت بحرانی"; |
|
|
|
"وضعیت بحرانی" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return ( |
|
|
|
return " وضعیت پایدار"; |
|
|
|
" وضعیت پایدار" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
})()}{" "} |
|
|
|
})()}{" "} |
|
|
|
|
|
|
|
|
|
|
|
</option> |
|
|
|
</option> |
|
|
|
))} |
|
|
|
))} |
|
|
|
|
|
|
|
|
|
|
|
</select> |
|
|
|
</select> |
|
|
|
</label> |
|
|
|
</label> |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const BasicTable = () => { |
|
|
|
const BasicTable = () => { |
|
|
@ -232,7 +221,6 @@ const BasicTable = () => { |
|
|
|
{">>"} |
|
|
|
{">>"} |
|
|
|
</button> |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{/* */} |
|
|
|
{/* */} |
|
|
|
{/* toggle columns */} |
|
|
|
{/* toggle columns */} |
|
|
@ -286,7 +274,9 @@ const BasicTable = () => { |
|
|
|
{page.map((row, idx) => { |
|
|
|
{page.map((row, idx) => { |
|
|
|
prepareRow(row); |
|
|
|
prepareRow(row); |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<tr {...row.getRowProps()}
|
|
|
|
<React.Fragment> |
|
|
|
|
|
|
|
<tr |
|
|
|
|
|
|
|
{...row.getRowProps()} |
|
|
|
// className={isEven(idx) ? "bg-gray-600" : "bg-white"}
|
|
|
|
// className={isEven(idx) ? "bg-gray-600" : "bg-white"}
|
|
|
|
> |
|
|
|
> |
|
|
|
{row.cells.map((cell) => { |
|
|
|
{row.cells.map((cell) => { |
|
|
@ -302,6 +292,14 @@ const BasicTable = () => { |
|
|
|
); |
|
|
|
); |
|
|
|
})} |
|
|
|
})} |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
|
|
|
|
{row.isExpanded ? ( |
|
|
|
|
|
|
|
<tr> |
|
|
|
|
|
|
|
<td colSpan={headerGroups[0].headers.length}> |
|
|
|
|
|
|
|
{renderRowSubComponent({ row: row.values })} |
|
|
|
|
|
|
|
</td> |
|
|
|
|
|
|
|
</tr> |
|
|
|
|
|
|
|
) : null} |
|
|
|
|
|
|
|
</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; |
|
|
|