Example: Client picker dialog
Use a client table inside a dialog to pick related records without touching the page URL.
"use client";
import { useState } from "react";
import type { ColumnDef } from "@tanstack/react-table";
import { DataTable, DataTableColumnHeader } from "@/components/datatable";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
type Candidate = { id: string; name: string; email: string };
const columns: ColumnDef<Candidate>[] = [
{
id: "name",
accessorKey: "name",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Name" />
),
enableColumnFilter: true,
meta: { variant: "text", label: "Name", placeholder: "Search..." },
},
{
id: "email",
accessorKey: "email",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Email" />
),
enableColumnFilter: true,
meta: { variant: "text", label: "Email" },
},
];
export function AssignUsersDialog({
open,
onOpenChange,
candidates,
onConfirm,
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
candidates: Candidate[];
onConfirm: (selected: Candidate[]) => void;
}) {
const [selected, setSelected] = useState<Candidate[]>([]);
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="flex h-[80vh] max-w-3xl flex-col">
<DialogHeader>
<DialogTitle>Select users</DialogTitle>
</DialogHeader>
<DataTable<Candidate>
columns={columns}
source={{ type: "client", data: candidates }}
disableParamPersistence
fillHeight
stickyHeader
enableToolbar
enablePagination
enableRowSelection
initialState={{ pagination: { pageIndex: 0, pageSize: 8 } }}
getRowId={(r) => r.id}
onSelectionChange={setSelected}
/>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button
disabled={selected.length === 0}
onClick={() => {
onConfirm(selected);
onOpenChange(false);
}}
>
Assign ({selected.length})
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
Why client mode here: candidates are already loaded (or cheap to load once). Filtering stays snappy without /list round-trips while the dialog is open.