Dashboard widgets
The dashboard home combines widgets with the resource cards. A widget is one file that returns data; the panel renders it. The three types mirror Filament’s stats overview, chart, and table widgets; custom widgets are not included in this alpha.
| Type | What it shows |
|---|---|
stats |
A row of stat cards: value, description, icon, color, optional sparkline |
chart |
A line, area, bar, pie, or doughnut chart |
table |
A small read-only table with resource-style columns |
Widgets are server-rendered. Their data() function runs on the server with the
same scoped Prisma client as an action handler, and only the resulting values are
sent to the browser.

Create a widget
Section titled “Create a widget”pnpm dashild make:widget RevenueOverview --statspnpm dashild make:widget OrdersChart --chart barpnpm dashild make:widget LatestOrders --tableThe command writes src/dashild/widgets/<name>.ts and registers the export in
panel.ts. The file is write-once: running the command again never
overwrites your work.
| Flag | Meaning |
|---|---|
--stats / --info |
Stat cards (default) |
--chart [type] |
Chart; type is line (default), area, bar, pie, or doughnut |
--table |
Table |
--width <width> |
full, half, third, or two-thirds |
--dir <path> |
Widgets folder; defaults to src/dashild/widgets |
--no-register |
Write the file without touching panel.ts |
--dry-run |
Print the file without writing it |
The panel keeps them next to the resources:
export const panel = definePanel({ title: "Admin", path: "/admin", resources: [postResource], widgets: [revenueOverviewWidget, ordersChartWidget, latestOrdersWidget], auth: { getCurrentUser, signOut },});Stats widgets
Section titled “Stats widgets”A stats widget returns an array, one entry per card:
import { defineWidget } from "@dashild/core";
interface ScopedClient { order: { count(args?: { where?: Record<string, unknown> }): Promise<number>; aggregate(args: { where?: Record<string, unknown>; _sum: { total: true }; }): Promise<{ _sum: { total: unknown } }>; };}
export const revenueOverviewWidget = defineWidget({ type: "stats", title: "Store overview", description: "Live numbers from the shop.", width: "full",
async data({ db }) { const client = db as ScopedClient; const [revenue, orders] = await Promise.all([ client.order.aggregate({ where: { status: { in: ["PAID", "SHIPPED"] } }, _sum: { total: true }, }), client.order.count(), ]);
return [ { label: "Revenue", value: `€${Number(revenue._sum.total ?? 0).toFixed(2)}`, description: "Paid and shipped orders", descriptionIcon: "trending-up", color: "success", }, { label: "Orders", value: orders, description: "All orders", descriptionIcon: "shopping-cart", }, ]; },});Each item accepts:
labelandvalue(required).descriptionanddescriptionIcon(a built-in icon name or one fromsrc/dashild/icons.tsx).color:default,info,success,warning, ordanger.chart: an array of numbers for a small sparkline.href: makes the whole card a link.
Chart widgets
Section titled “Chart widgets”A chart returns labels and one or more datasets, the same shape Chart.js
uses. The ScopedClient interface is the same idea as the stats example: declare
only the delegates this widget calls.
export const ordersChartWidget = defineWidget({ type: "chart", chart: "doughnut", title: "Orders by status", description: "Current orders grouped by state.", width: "half",
async data({ db }) { const client = db as ScopedClient; const groups = await client.order.groupBy({ by: ["status"], _count: { _all: true }, }); const counts = new Map( groups.map((group) => [group.status, group._count._all]), );
return { labels: ["Pending", "Paid", "Shipped", "Cancelled"], datasets: [ { label: "Orders", data: ["PENDING", "PAID", "SHIPPED", "CANCELLED"].map( (status) => counts.get(status) ?? 0, ), }, ], }; },});chart:line,area,bar,pie, ordoughnut.labels: one label per data point.datasets: each dataset has alabel, adataarray, and an optionalcolor. Without a color, the theme’s chart palette is used.- Pie and doughnut charts use the first dataset; each label becomes a slice.
Charts render with Recharts on the client. The data is plain JSON, so the widget itself stays on the server.

Table widgets
Section titled “Table widgets”A table widget returns columns and rows. Columns use the same format as a
resource table. Declare the delegates you query on ScopedClient as in the stats
example:
export const latestOrdersWidget = defineWidget({ type: "table", title: "Latest orders", width: "half", empty: "No orders yet.", columns: [ { field: "number", label: "Number" }, { field: "customer", label: "Customer", display: "name" }, { field: "status", label: "Status", format: "badge", tone: { PENDING: "accent", PAID: "green", CANCELLED: "danger" }, }, { field: "total", label: "Total", format: "currency", currency: "EUR" }, { field: "createdAt", label: "Created", format: "datetime" }, ],
async data({ db }) { const client = db as ScopedClient; const rows = await client.order.findMany({ take: 5, orderBy: { createdAt: "desc" }, include: { customer: { select: { id: true, name: true } } }, });
return rows.map((row) => ({ id: row.id, number: row.number, customer: row.customer ? { id: row.customer.id, display: row.customer.name } : null, status: row.status, total: row.total, createdAt: row.createdAt, })); },});format supports text, number, currency, date, datetime, badge, and
json. For a relation column, map the row to { id, display } and set
display on the column, exactly as above. empty is the text shown when there
are no rows.
The data context
Section titled “The data context”data() receives:
| Value | Description |
|---|---|
db |
Prisma extended with the user’s policy scope |
user |
The signed-in user (id, email, name, organizationId, roles) |
locale |
en or es |
now |
A stable Date for ranges such as “the last 30 days” |
db is typed as unknown because core does not depend on a generated Prisma
client. Cast it to the delegates the widget uses, like the action handlers do.
Security: db applies the same policy scope as the resource tables. A widget
that counts orders counts only the orders the user can read. Models without a
Dashild resource pass through unchanged; a resource with a missing policy fails
closed.
canView hides a widget for some users before data() runs:
canView: ({ user }) => user.roles?.includes("ADMIN") ?? false,It is a UI convenience, not a security boundary. The scope on db is the
security boundary.
Layout
Section titled “Layout”width:full(default for stats and tables),half(default for charts),third, ortwo-thirds.sort: lower numbers render first; ties keep the panel order.- Stats widgets lay their cards out automatically: one to four fit in a row on wide screens and stack on mobile.
Limits in this alpha
Section titled “Limits in this alpha”- Widgets load on every dashboard request; there is no polling or lazy loading.
- Custom React widgets are not supported yet: use stats, charts, and tables.
- Dashboard-wide filters are not available yet; query the range inside
data(). - A widget error shows a generic “could not be loaded” card and logs the error on the server, so one broken widget does not take down the dashboard.
Troubleshooting
Section titled “Troubleshooting”- The widget does not appear: check that it is in
panel.tsand thatcanViewreturns true. - The chart is empty:
labelsand every dataset’sdatamust be arrays of the same length. - A relation column is blank: return
{ id, display }for that field and setdisplayon the column. - The numbers ignore the tenant: the widget is not using
dbfrom the context, or the model has no policy entry. - Pie colors are all the same: omit
colorto use the palette; a datasetcoloris applied to the whole series.