added sorting in ascending order
This commit is contained in:
parent
b400acf23f
commit
23d676c96a
@ -7,28 +7,48 @@ const MasterTable = ( {data, columns, loading, handleModalData} ) =>
|
|||||||
{
|
{
|
||||||
const hasMasterPermission = useHasUserPermission(MANAGE_MASTER)
|
const hasMasterPermission = useHasUserPermission(MANAGE_MASTER)
|
||||||
const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster)
|
const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster)
|
||||||
const hiddenColumns = ["id", "featurePermission","tenant","tenantId","checkLists"];
|
const hiddenColumns = [ "id", "featurePermission", "tenant", "tenantId", "checkLists" ];
|
||||||
|
|
||||||
const safeData = Array.isArray(data) ? data : [];
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const [itemsPerPage] = useState(10);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = safeData.slice( indexOfFirstItem, indexOfLastItem );
|
|
||||||
|
|
||||||
useEffect(() => {
|
const safeData = Array.isArray(data) ? data : [];
|
||||||
setCurrentPage(1);
|
|
||||||
}, [ safeData ] )
|
|
||||||
|
|
||||||
const paginate = (pageNumber) => setCurrentPage(pageNumber);
|
|
||||||
const totalPages = Math.ceil(safeData.length / itemsPerPage);
|
|
||||||
|
|
||||||
const updatedColumns = columns
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const [itemsPerPage] = useState(10);
|
||||||
|
|
||||||
|
const sortKeys = {
|
||||||
|
"Application Role": "role",
|
||||||
|
Activity: "activityName",
|
||||||
|
"Job Role": "name",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const sortKey = sortKeys[selectedMaster];
|
||||||
|
const sortedData = [...safeData].sort((a, b) => {
|
||||||
|
if (!sortKey) return 0;
|
||||||
|
const aValue = a[sortKey] || "";
|
||||||
|
const bValue = b[sortKey] || "";
|
||||||
|
return aValue.localeCompare(bValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pagination logic
|
||||||
|
const indexOfLastItem = currentPage * itemsPerPage;
|
||||||
|
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
||||||
|
const currentItems = sortedData.slice(indexOfFirstItem, indexOfLastItem);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentPage(1);
|
||||||
|
}, [safeData]);
|
||||||
|
|
||||||
|
const paginate = (pageNumber) => setCurrentPage(pageNumber);
|
||||||
|
const totalPages = Math.ceil(safeData.length / itemsPerPage);
|
||||||
|
|
||||||
|
const updatedColumns = columns
|
||||||
.filter((col) => !hiddenColumns.includes(col.key))
|
.filter((col) => !hiddenColumns.includes(col.key))
|
||||||
.map((col) => ({
|
.map((col) => ({
|
||||||
...col,
|
...col,
|
||||||
label:
|
label:
|
||||||
col.key === "role" || col.key === "activityName" || col.key === "status" ? "Name" : col.label,
|
col.key === "role" || col.key === "activityName" || col.key === "name"
|
||||||
|
? "Name"
|
||||||
|
: col.label,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user