gridcn2.0.0
Style examples

Loading state example

Show a skeleton, a progress bar, or the empty state with the loading prop, and replace each display with your own.

The loading prop and the number of rows in view decide what the grid shows. In the demo, the Loading switch sets loading, and the Rows present switch adds or removes the rows. Together they reach every state in the table.

Toggle both switches: Loading with no rows shows a viewport-filling skeleton, Loading with rows present shows a slim bar under the header instead, and rows-off + loading-off is the ordinary empty state.

Name
Email
Role
Score
Silent Tiger
user0@example.com
Viewer
4
Quick Lion
user1@example.com
Viewer
89
Swift Wolf
user2@example.com
Manager
80
Eager Lion
user3@example.com
User
51
Eager Tiger
user4@example.com
Viewer
83
Silent Wolf
user5@example.com
User
15
Swift Lion
user6@example.com
Viewer
62
Eager Lion
user7@example.com
Manager
42
Eager Eagle
user8@example.com
Editor
35
Bold Tiger
user9@example.com
Editor
52
pnpm dlx shadcn@latest add @gridcn/data-grid-loading-demo
Rows in viewloadingThe grid shows
nonetrueSkeleton rows that fill the viewport.
sometrueA slim indeterminate bar under the header. The rows stay on screen.
nonefalseThe empty state, with the text labels.grid.emptyState, or labels.grid.noResults when a filter or a server search hides every row.

Where the data comes from

loading changes what the grid shows and fetches nothing. Pass the flag from the code that owns your request. The server rows hook returns loading in gridProps.

Customizing the look

While loading is true, loadingState replaces the skeleton and the bar. It takes a node, or a function that receives { reason }. If no rows are in view, the reason is "no-data". If rows are in view, it is "rows-present". The grid renders the result under the header at full width, and the result owns its accessibility.

emptyState takes the same two forms. If data is empty and no server filter or search is active, its reason is "no-data". In every other case the reason is "filtered".

The sample passes data without onDataChange, so it sets readOnly:

import { DataGrid, defineColumns } from "@/components/data-grid/data-grid";

type Order = { id: string; customer: string };

const columns = defineColumns<Order>()([
  { id: "customer", header: "Customer", accessorKey: "customer" },
]);

export function Orders({ rows, loading }: { rows: Order[]; loading: boolean }) {
  return (
    <DataGrid
      className="h-80"
      data={rows}
      columns={columns}
      readOnly
      loading={loading}
      loadingState={({ reason }) => (
        <p className="p-4 text-sm">
          {reason === "no-data" ? "Fetching orders…" : "Refreshing…"}
        </p>
      )}
      emptyState={({ reason }) =>
        reason === "filtered" ? "No order matches" : "No orders yet"
      }
    />
  );
}

On this page