Back to blog
December 4, 2026•50 views

React Data Grid: Build From Scratch vs Open-Source Libraries

react data gridtanstack tableag gridreact dashboardnext.jsbuild vs buy
React Data Grid: Build From Scratch vs Open-Source Libraries

Every dashboard I build eventually hits the same fork. Someone drops a requirement like "we need a sortable, filterable table with 40,000 rows and inline editing" and I have to decide whether to write the grid myself or pull one in. I have done both, more times than I care to count, and the wrong choice costs weeks. So here is the comparison I wish I had early on: what a custom build actually costs, where open-source options like TanStack Table and AG Grid fit, and how to pick without guessing.

I lead web engineering and AI automation at AKIJ iBOS, where data grids show up in almost every admin panel, CRM and analytics dashboard we ship. This article is the decision process I use now, with the trade-offs I have paid for in real projects.

A note on sourcing: feature and licensing details for third-party libraries change between releases. Verify the specifics against each project's current documentation before committing, links are included below where they help.

Why the data grid decision matters more than it looks

A table feels like a small component. It is not. A "real" grid needs sorting, filtering, pagination or virtualization, column resizing, row selection, keyboard navigation, accessible focus management, and usually editing with validation. Each of those is a small project. Stack them and you have a subsystem that can dominate your dashboard's maintenance budget.

The grid also tends to be the first thing users judge. If scrolling stutters at 10,000 rows, the whole app feels slow even if everything else is fast. So the build vs buy question is really two questions: how much control do you need, and how much time can you afford to spend owning it?

The three real options (it is not just build vs buy)

Most articles frame this as custom vs library. In practice there are three paths, and the middle one is where I spend most of my time.

  1. Fully custom grid built on plain React, useState, and CSS. You own everything.
  2. Headless library (TanStack Table, or a lightweight grid that ships logic plus a thin rendering layer). You get the hard parts and keep full control of markup and styling.
  3. Batteries-included grid (AG Grid, MUI X DataGrid, Handsontable). You get everything, including the parts you did not ask for, plus licensing terms to read carefully.

The headless option is the one people underrate. It is usually the right answer for a product dashboard where design matters and the data model is yours.

What building a React data grid from scratch actually involves

I want to be honest about scope, because "I'll just build a table" is how sprints die. A minimal grid that handles sorting and filtering is a day or two. A production grid is more like this:

  • Virtualization. You need windowing for large datasets. @tanstack/react-virtual or a hand-rolled scroll observer. Get the row height wrong and you get scroll jumps.
  • Sorting and multi-sort. Comparators, stable sort, null handling, sort indicators, and URL state so the view is shareable.
  • Filtering. Per-column filters, global search, debounced input, and combining filters with sort correctly.
  • Selection and bulk actions. Shift-click ranges, select-all semantics across pages, and keeping selection stable when data refetches.
  • Editing. Cell edit mode, validation, optimistic updates, and rollback on API failure.
  • Accessibility. Roving tabindex, aria-sort, aria-rowcount, keyboard navigation. This is where custom grids quietly fail audits. The ARIA Authoring Practices Guide grid pattern is the reference to build against.
  • Column management. Resize, reorder, show/hide, persist preferences per user.

Here is the shape of a small custom grid with virtualization, roving tabindex and arrow-key navigation wired in, just to show the moving parts:

import { useVirtualizer } from "@tanstack/react-virtual";
import { useMemo, useRef, useState } from "react";

type Row = { id: number; name: string; revenue: number };
type SortKey = keyof Omit<Row, "id">;
const COLUMNS: SortKey[] = ["name", "revenue"];

export function CustomGrid({ rows }: { rows: Row[] }) {
  const [sortKey, setSortKey] = useState<SortKey>("revenue");
  const [asc, setAsc] = useState(false);
  // Roving tabindex: which header currently owns the tab stop, and where focus is.
  const [activeCol, setActiveCol] = useState(0);
  const headerRefs = useRef<Array<HTMLDivElement | null>>([]);
  const parentRef = useRef<HTMLDivElement>(null);

  const sorted = useMemo(() => {
    const copy = [...rows];
    copy.sort((a, b) => {
      const av = a[sortKey], bv = b[sortKey];
      const cmp = av < bv ? -1 : av > bv ? 1 : 0;
      return asc ? cmp : -cmp;
    });
    return copy;
  }, [rows, sortKey, asc]);

  const virtualizer = useVirtualizer({
    count: sorted.length,
    getScrollElement: () => parentRef.current,
    estimateSize: () => 40,
    overscan: 12,
  });

  const toggleSort = (key: SortKey) => {
    if (key === sortKey) setAsc((v) => !v);
    else {
      setSortKey(key);
      setAsc(true);
    }
  };

  const ariaSort = (key: SortKey) =>
    key === sortKey ? (asc ? "ascending" : "descending") : "none";

  const focusCol = (index: number) => {
    const next = Math.max(0, Math.min(COLUMNS.length - 1, index));
    setActiveCol(next);
    headerRefs.current[next]?.focus();
  };

  const onHeaderKeyDown = (e: React.KeyboardEvent, index: number) => {
    const key = COLUMNS[index];
    switch (e.key) {
      case "ArrowRight":
        e.preventDefault();
        focusCol(index + 1);
        break;
      case "ArrowLeft":
        e.preventDefault();
        focusCol(index - 1);
        break;
      case "Home":
        e.preventDefault();
        focusCol(0);
        break;
      case "End":
        e.preventDefault();
        focusCol(COLUMNS.length - 1);
        break;
      case "Enter":
      case " ":
        e.preventDefault();
        toggleSort(key);
        break;
    }
  };

  return (
    <div
      ref={parentRef}
      role="grid"
      aria-rowcount={sorted.length}
      aria-colcount={COLUMNS.length}
      style={{ height: 480, overflow: "auto" }}
    >
      <div role="row" style={{ position: "sticky", top: 0, display: "flex" }}>
        {COLUMNS.map((key, index) => (
          <div
            key={key}
            ref={(el) => { headerRefs.current[index] = el; }}
            role="columnheader"
            aria-sort={ariaSort(key)}
            // Only the active header is tabbable; arrows move focus between them.
            tabIndex={index === activeCol ? 0 : -1}
            onFocus={() => setActiveCol(index)}
            onKeyDown={(e) => onHeaderKeyDown(e, index)}
            onClick={() => toggleSort(key)}
            style={{ flex: 1, cursor: "pointer", userSelect: "none" }}
          >
            {key}
            {key === sortKey ? (asc ? " ▲" : " ▼") : ""}
          </div>
        ))}
      </div>
      <div style={{ height: virtualizer.getTotalSize(), position: "relative" }}>
        {virtualizer.getVirtualItems().map((v) => {
          const row = sorted[v.index];
          return (
            <div
              key={row.id}
              role="row"
              aria-rowindex={v.index + 2}
              style={{
                position: "absolute",
                top: 0,
                transform: `translateY(${v.start}px)`,
                height: v.size,
                display: "flex",
              }}
            >
              <div role="gridcell" style={{ flex: 1 }}>{row.name}</div>
              <div role="gridcell" style={{ flex: 1 }}>{row.revenue}</div>
            </div>
          );
        })}
      </div>
    </div>
  );
}

That is the easy 20%. The remaining 80% is edge cases: empty states, loading skeletons, error boundaries, sticky headers, column resize persistence, and the accessibility work. I have watched a "quick" custom grid turn into three weeks of polish. It is fine if you planned for it. It is painful if you did not.

Open-source options worth comparing

Here is where I land on the main contenders for a dashboard grid. I am deliberately including a couple of lighter open-source options alongside the enterprise ones, because the middle ground is where most product dashboards actually fit.

Option Model Best for Watch out for
Custom build You own it Very specific UX, small datasets, full brand control Accessibility, virtualization, editing cost; long-term maintenance
TanStack Table v8 Headless Full control of markup and styling, custom design systems You build the UI; virtualization is a separate add-on
AG Grid Batteries-included Enterprise features: pivoting, grouping, tree data, server-side row model Community vs Enterprise licensing; bundle size; learning curve
MUI X DataGrid Batteries-included, MUI-native Teams already on Material UI Advanced features sit in paid Pro/Premium tiers
Handsontable Spreadsheet-like Excel-style editing, formulas Commercial license required for many non-open-source uses; check terms

TanStack Table is my usual starting point for the headless path: it gives you the sorting, filtering and grouping model, and you keep the markup. Here is a thin integration that pairs it with virtualization, so you can see how little glue code the headless route actually needs:

import {
  flexRender,
  getCoreRowModel,
  getSortedRowModel,
  useReactTable,
  type ColumnDef,
  type SortingState,
} from "@tanstack/react-table";
import { useVirtualizer } from "@tanstack/react-virtual";
import { useRef, useState } from "react";

export function TanStackGrid<T>({ columns, data }: {
  columns: ColumnDef<T, any>[];
  data: T[];
}) {
  const [sorting, setSorting] = useState<SortingState>([]);
  const table = useReactTable({
    data,
    columns,
    state: { sorting },
    onSortingChange: setSorting,
    getCoreRowModel: getCoreRowModel(),
    getSortedRowModel: getSortedRowModel(),
  });

  const parentRef = useRef<HTMLDivElement>(null);
  const rows = table.getRowModel().rows;
  const virtualizer = useVirtualizer({
    count: rows.length,
    getScrollElement: () => parentRef.current,
    estimateSize: () => 40,
    overscan: 12,
  });

  return (
    <div ref={parentRef} style={{ height: 480, overflow: "auto" }}>
      <table>
        <thead>
          {table.getHeaderGroups().map((hg) => (
            <tr key={hg.id}>
              {hg.headers.map((header) => (
                <th
                  key={header.id}
                  aria-sort={
                    header.column.getIsSorted() === "asc" ? "ascending"
                    : header.column.getIsSorted() === "desc" ? "descending"
                    : "none"
                  }
                  onClick={header.column.getToggleSortingHandler()}
                >
                  {flexRender(header.column.columnDef.header, header.getContext())}
                </th>
              ))}
            </tr>
          ))}
        </thead>
        <tbody>
          {virtualizer.getVirtualItems().map((v) => {
            const row = rows[v.index];
            return (
              <tr
                key={row.id}
                style={{ position: "absolute", top: 0, transform: `translateY(${v.start}px)` }}
              >
                {row.getVisibleCells().map((cell) => (
                  <td key={cell.id}>
                    {flexRender(cell.column.columnDef.cell, cell.getContext())}
                  </td>
                ))}
              </tr>
            );
          })}
        </tbody>
      </table>
    </div>
  );
}

That is the whole integration: the library owns the sort model, you own the pixels. For a lot of internal dashboards and SaaS admin panels, this is the sweet spot, you are not rebuilding sorting and virtualization, and you are not adopting a large enterprise dependency with a license matrix.

Build vs buy: a decision matrix I actually use

When a client asks me to pick, I run through this in my head in about two minutes. You can steal it.

Question If yes If no
Do you need pivoting, tree data, or server-side row model? AG Grid Enterprise or similar Keep looking at lighter options
Is the dataset over ~5,000 rows? Virtualization required (TanStack + virtual, AG Grid) Plain table is fine
Does the design system require pixel-perfect custom cells? Headless (TanStack Table) Styled grid is fine
Is the team junior or short on time? Buy (library) Custom is viable
Is accessibility a hard requirement (gov, enterprise, healthcare)? Library with tested a11y Custom with care
Will this grid live for 3+ years with changing requirements? Library, so you are not maintaining a subsystem Custom is fine
Is budget near zero and the team senior? Open-source headless Consider paid tiers

My default recommendation for most product dashboards: start with a headless or lightweight open-source grid, not a custom build. Reserve a custom grid for genuinely unusual UX or tiny datasets where a library is overkill.

Performance: where each option actually struggles

Performance is the most over-claimed part of this comparison. Real numbers depend on your rows, cell renderers and hardware, so treat any "100k rows at 60fps" claim with suspicion, including mine. What I can tell you is where each approach breaks first.

  • Custom grids break at the cell renderer. If every cell mounts a component with hooks, 10,000 rows will crawl even with virtualization, because overscan multiplies the mounted cells. Fix: render plain text, memoize, avoid per-cell state.
  • Headless libraries are only as fast as your rendering. TanStack gives you the model; if your row component re-renders on every parent state change, you will feel it. Fix: React.memo, stable callbacks, and keep selection state out of the row when possible.
  • Batteries-included grids are usually optimized out of the box, but they can be heavy on first load and their internal renderers can fight your custom cells. Measure bundle impact before committing.

One measured example from my own work: on a 20,000-row customer table, the first version of the custom grid mounted a formatted-currency component in every revenue cell. Scrolling dropped to roughly 18-22 FPS in Chrome with 4x CPU throttling, and the main thread spent most of each frame re-rendering off-screen cells. Replacing the cell component with a pre-formatted string (computed once per row with Intl.NumberFormat) and wrapping the row in React.memo brought it back to a steady ~60 FPS on the same machine and dataset. The grid code barely changed, the cell renderer was the entire bottleneck.

If you want a fair benchmark, build the same 50,000-row dataset across two options with identical cell content, throttle the CPU to 4x in DevTools, and record time-to-interactive and scroll FPS. Do not trust blog numbers without a methodology. I have seen the same library described as both "blazing fast" and "unusable" in the same week, because one author virtualized and the other did not.

If your grid sits inside a Next.js app, rendering strategy matters as much as the grid itself. I cover the trade-offs of server rendering versus client-side interactivity in my guide to Next.js streaming and Server Components for founders, which is worth reading before you decide where the grid should live.

The maintenance and hiring angle

This is the part founders rarely weigh, and it matters if you are hiring. A custom grid is a skill concentration risk. If the developer who built it leaves, the next person inherits undocumented virtualization, keyboard handling and edit state. A widely used library is a known quantity: any competent React developer can pick it up, and there are docs, issues and community answers.

For teams hiring remote developers, that portability is worth real money. When you hire a Next.js developer for a dashboard, you want them productive on day one, not reverse-engineering a bespoke grid. Libraries lower onboarding cost. Custom grids raise it, and that cost is invisible until someone quits.

If you are the founder evaluating candidates, ask how they would handle a 20,000-row editable grid. Someone who says "I'd build it from scratch" without mentioning virtualization is either very confident or has not shipped one. Someone who names two libraries and the trade-offs has probably been burned before, which is a good sign.

When I still build a custom grid

I am not anti-custom. I build from scratch when:

  • The dataset is small (under a few hundred rows) and the UX is unusual, like a kanban-style layout with grid semantics.
  • The grid is a marketing or landing-page element where bundle size is everything and interactivity is minimal.
  • The client needs a very specific interaction that no library supports without fighting it.

In those cases a lean custom component is fewer lines than configuring a library, and it will not surprise anyone later.

A practical setup for the open-source path

If you go with a library, keep the integration thin. Here is the pattern I use with a Next.js App Router dashboard, wrapping the grid in a client component and keeping data fetching on the server.

// app/customers/grid.tsx
"use client";
import { useMemo, useState } from "react";
import { TanStackGrid } from "@/components/tanstack-grid";
import { customerColumns } from "./columns";

export function CustomersGrid({ rows }: { rows: Customer[] }) {
  const [query, setQuery] = useState("");
  const filtered = useMemo(
    () => rows.filter((r) => r.name.toLowerCase().includes(query.toLowerCase())),
    [rows, query]
  );
  return (
    <section>
      <input
        value={query}
        onChange={(e) => setQuery(e.target.value)}
        placeholder="Search customers"
        aria-label="Search customers"
      />
      <TanStackGrid columns={customerColumns} data={filtered} />
    </section>
  );
}

Two rules that save me every time: keep the grid in its own client component so the rest of the page stays server-rendered, and keep filter/sort state in the URL so a refresh does not lose the user's view.

If your dashboard also needs to load large datasets from an API, the cost and cold-start trade-offs of serverless endpoints are worth understanding up front, I walk through them in building a serverless API with Next.js and AWS Lambda.

Conclusion

The comparison comes down to ownership versus speed. A custom grid gives you total control and a maintenance bill you pay later. A library gets you to a working dashboard faster and makes the codebase easier to hand off. For most product and admin dashboards I reach for a headless option like TanStack Table, and I only hand-roll when the UX genuinely demands it.

If you are building a dashboard and stuck on this decision, or you need someone to ship it properly with Next.js and the right grid under the hood, that is exactly the work I do. You can reach out through my site and we can talk through your data model before you commit to a library.

Frequently asked questions

Should I build my own React data grid or use a library?

Build your own only if the dataset is small (a few hundred rows), the UX is unusual, or you have senior React developers with time for accessibility and virtualization. For most dashboards, an open-source grid saves weeks and is easier to hand off.

How do I make a React data grid fast with large datasets?

Virtualize rows so only visible ones mount, render plain text instead of heavy cell components, memoize row components with stable callbacks, and keep selection state out of individual rows. In one of my own grids, swapping a per-cell currency component for a pre-formatted string took a 20,000-row table from roughly 20 FPS to a steady 60 FPS under 4x CPU throttling.

How does TanStack Table handle accessibility compared to AG Grid?

TanStack Table is headless, so it gives you the sort and filter model but not the markup, you are responsible for aria-sort, roving tabindex and keyboard navigation, as shown in the snippet above. AG Grid ships its own accessible grid markup out of the box, which is a real advantage if a11y is a hard requirement and your team lacks the time to build it.

What is the best React data grid for a Next.js dashboard?

It depends on features, TanStack Table suits custom design systems, AG Grid fits enterprise feature sets like pivoting and tree data, and MUI X fits teams already on Material UI. Keep the grid in a client component and leave data fetching on the server.

Share this post

Native Web Share is available on mobile, so that share sheet includes Instagram and any other app you have installed.

Let's Connect

Get In Touch

Let's build something premium together.

Contact info

Follow me
Chat on WhatsApp