I'm trying to handle a sort function that toggles between dsc and asc. It also needs to handle a certain table column name which is referred to as "header". The expected outcome is to sort either "days" or "station" and have it toggle separately between dsc and asc.
handleClick={(val: any, header: string) =>
val((val: any) => {
const result = [...val].sort((a: any, b: any) => {
return sortOrder === 'asc'
? header === 'Station'
? b.station - a.station
: b.days - a.days
: header === 'Station'
? a.station - b.station
: a.days - b.days;
});
setSortOrder(sortOrder === 'asc' ? 'dsc' : 'asc');
return result;
})
}
This is my current function station filters properly but "Days Since Last Event" doesn't seem to work.
This is the handleClick on the child function
onClick={() => props.handleClick(setFilteredData, header)}
This is the sample of the data
[
{
days: 23,
station: "Braidwood",
},
{
days: 18,
station: "Byron",
},
{
days: 28,
station: "Byron",
},
{
days: 32,
station: "Calvert Cliffs",
},
{
days: 20,
station: "Dresden",
},
{
days: 320,
station: "Dresden",
},
];