From fe3d9ac852de79a2c7a046a02f3cea75f7c816b9 Mon Sep 17 00:00:00 2001 From: Monirul Date: Fri, 20 Feb 2026 00:17:16 +0530 Subject: [PATCH] Added table sorting. next up: filtering --- frontend/app/all-customers/columns.tsx | 31 ++++++++++++++++++++--- frontend/app/all-customers/data-table.tsx | 11 ++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/frontend/app/all-customers/columns.tsx b/frontend/app/all-customers/columns.tsx index 5a3ebe6..3836b31 100644 --- a/frontend/app/all-customers/columns.tsx +++ b/frontend/app/all-customers/columns.tsx @@ -1,7 +1,7 @@ "use client"; import { ColumnDef } from "@tanstack/react-table"; -import { Ghost, MoreHorizontal } from "lucide-react"; +import { MoreHorizontal, ArrowUpDown } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, @@ -29,7 +29,19 @@ export const columns: ColumnDef[] = [ }, { accessorKey: "name", - header: "Name", + header: ({ column }) => { + return ( +
+ +
+ ); + }, }, { accessorKey: "occupation", @@ -46,7 +58,20 @@ export const columns: ColumnDef[] = [ }, { accessorKey: "balance", - header: () =>
Balance
, + // header: () =>
Balance
, + header: ({ column }) => { + return ( +
+ +
+ ); + }, cell: ({ row }) => { const amount = parseFloat(row.getValue("balance")); const formatted = new Intl.NumberFormat("en-IN", { diff --git a/frontend/app/all-customers/data-table.tsx b/frontend/app/all-customers/data-table.tsx index 4105c31..99e164c 100644 --- a/frontend/app/all-customers/data-table.tsx +++ b/frontend/app/all-customers/data-table.tsx @@ -1,11 +1,15 @@ "use client"; +import { useState } from "react"; + import { ColumnDef, flexRender, getCoreRowModel, getPaginationRowModel, useReactTable, + SortingState, + getSortedRowModel, } from "@tanstack/react-table"; import { @@ -35,11 +39,18 @@ export function DataTable({ columns, data, }: DataTableProps) { + const [sorting, setSorting] = useState([]); + const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), + onSortingChange: setSorting, + getSortedRowModel: getSortedRowModel(), + state: { + sorting, + }, }); return (