I’ve implemented desc sort, which is a client event click the table header to toggle the sort order, however in the meanwhile, I make the Prisma client take the sort order from the query params and pass it into the prisma.issues.findMany() to query the ‘asc’ or ‘desc’ ordered issues from the backend.
I got the ascend/descend sort ordering to work using the same structure as Mosh (no change of server/clients components or additional components). But interestingly it works great in development, but is flaky in production which I cannot figure out why. In production the searchParams don’t always update on a click, plus using the status filter doesn’t reset when ‘All’ is selected (the extisting status searchParam remains in the url… most of the time).
Here is the additional code snips I added to the production version at the end of the course
(I used some of the examples already outlined in this thread)
In IssueStatusFilter.tsx
In the onValueChange(status) handler I added the sortOrder searchParam if an orderBy param is present (if there is on orderBy searchParam, there will be a sortOrder searchParam also):
if (searchParams.get("orderBy")) {
params.append("orderBy", searchParams.get("orderBy")!);
params.append("sortOrder", searchParams.get("sortOrder")!);
}
Really fast and effective in developement, buy buggy and sluggish in production. Any ideas why???