forked from PolarisPyra/daphnis
added sorting
This commit is contained in:
parent
ecb9663f6d
commit
4a91c642b0
@ -12,11 +12,10 @@ import {
|
|||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { generateShareToken } from "@/app/(sharing)/[token]/token";
|
import { generateShareToken } from "@/app/(sharing)/[token]/token";
|
||||||
|
import { ArrowUpDown, MoreHorizontalIcon } from "lucide-react";
|
||||||
import { chuni_score_playlog } from "@/prisma/schemas/artemis/generated/artemis";
|
import { chuni_score_playlog } from "@/prisma/schemas/artemis/generated/artemis";
|
||||||
import { chuni_static_music } from "@/prisma/schemas/artemis/generated/artemis";
|
import { chuni_static_music } from "@/prisma/schemas/artemis/generated/artemis";
|
||||||
import { getGrade } from "@/lib/helpers";
|
import { getGrade } from "@/lib/helpers";
|
||||||
@ -48,7 +47,17 @@ export const columns: ColumnDef<chunithm>[] = [
|
|||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "score",
|
accessorKey: "score",
|
||||||
header: "Score",
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Score
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
cell: ({ row }) => <div>{row.original.score?.toLocaleString()}</div>,
|
cell: ({ row }) => <div>{row.original.score?.toLocaleString()}</div>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -69,7 +78,17 @@ export const columns: ColumnDef<chunithm>[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "userPlayDate",
|
accessorKey: "userPlayDate",
|
||||||
header: "Date",
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Date
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "difficulty",
|
accessorKey: "difficulty",
|
||||||
@ -94,6 +113,7 @@ export const columns: ColumnDef<chunithm>[] = [
|
|||||||
{
|
{
|
||||||
accessorKey: "Attempts",
|
accessorKey: "Attempts",
|
||||||
header: "Attempts",
|
header: "Attempts",
|
||||||
|
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="font-medium">{row.original.playCount}</div>
|
<div className="font-medium">{row.original.playCount}</div>
|
||||||
),
|
),
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
|
SortingState,
|
||||||
|
getSortedRowModel,
|
||||||
flexRender,
|
flexRender,
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
getPaginationRowModel,
|
getPaginationRowModel,
|
||||||
@ -16,6 +18,7 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
interface DataTableProps<TData, TValue> {
|
interface DataTableProps<TData, TValue> {
|
||||||
columns: ColumnDef<TData, TValue>[];
|
columns: ColumnDef<TData, TValue>[];
|
||||||
@ -26,12 +29,18 @@ export function DataTable<TData, TValue>({
|
|||||||
columns,
|
columns,
|
||||||
data,
|
data,
|
||||||
}: DataTableProps<TData, TValue>) {
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data,
|
data,
|
||||||
columns,
|
columns,
|
||||||
|
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user