Syncfusion® React Pivot Table – Next.js Server Quick Start
A production-ready quick start that connects the Syncfusion® React Pivot Table to a Next.js backend using built-in API Routes — enabling remote data binding and full CRUD operations over REST endpoints.
📑 Table of Contents
🚀 Quick Overview
This project demonstrates how to bind the Syncfusion® React Pivot Table to a remote Next.js backend using built-in API Routes (App Router). A single /api route handles data retrieval along with create, update, and delete operations through standard HTTP verbs (GET, POST, PUT, DELETE).
| Component |
Technology |
Purpose |
| 🎨 Frontend |
React 19 + Next.js 16 + Syncfusion® EJ2 |
Render the interactive Pivot Table UI |
| ⚙️ Backend |
Next.js API Routes (App Router) |
Serve data, perform CRUD, return JSON responses |
| 🔌 API Style |
REST (GET/POST/PUT/DELETE) |
Standard HTTP verbs map to CRUD actions |
| 📊 Sample Data |
In-memory productDetails (from app/data.ts) |
Simulate product sales records for the Pivot Table |
💡 Next.js API Routes are ideal when you want a single full-stack codebase that contains both the React client and the backend. The App Router (app/ directory) is required because the sample data and API route live in app/data.ts and app/api/route.ts.
✨ Key Features
- 📊 Remote Data Binding – Connects the Pivot Table to a Next.js API route over HTTP using the native
fetch API.
- 🔄 Full CRUD Support – Insert, update, and delete records directly from the Pivot Table drill-through grid.
- ⚙️ Built-in API Routes – Uses Next.js App Router route handlers (
app/api/route.ts) — no separate backend project required.
- 🗂️ Standardized Response Format – Returns data as
{ result, count } for the read endpoint, keeping responses predictable.
- 🔑 Primary Key Configuration – Uses
ProductID as the primary key for unique record identification during update and delete operations.
- 🎨 Tailwind 3 Theme – Preconfigured with the Syncfusion Tailwind 3 theme for a modern Pivot Table look and feel.
- ⚡ Drill-Through Editing – Double-click a pivot cell to add, edit, or delete underlying records in a pop-up grid.
- 🛡️ Robust Error Handling – API route returns meaningful HTTP status codes (
400, 404) and clear error messages.
- 📦 Ready-to-Run – Clone, install, and start — no database setup required (in-memory sample data).
🛠️ Prerequisites
Make sure the following software and packages are installed on your machine before running the project.
| Software / Package |
Version |
Purpose |
| 🟢 Node.js |
20.19+ or 22.12+ |
Runtime for the Next.js application |
| 📦 npm / yarn / pnpm |
Latest stable |
Package manager |
| ⚛️ React |
19.x or later |
Build the Pivot Table client |
| ⚡ Next.js |
14.x or later (App Router) |
React framework, file-based routing, and API routes |
| 📘 TypeScript |
5.x or later |
Supports TypeScript (.tsx) examples used in the application |
| 📦 @syncfusion/ej2-react-pivotview |
33.1.45+ |
React Pivot Table component |
| 📦 @syncfusion/ej2-pivotview |
33.1.45+ |
Base Syncfusion® package used for shared Pivot Table types |
| 📦 @syncfusion/ej2-data |
33.1.45+ |
Provides the DataManager and Query classes |
| 📦 @syncfusion/ej2-tailwind3-theme |
33.1.45+ |
Tailwind 3 theme styles for the Pivot Table |
📂 Project Structure
syncfusion-react-pivot-with-nextjs-server/
├── 📁 nextjs_pivot/ # Next.js application (client + API)
│ ├── 📁 app/ # App Router root
│ │ ├── data.ts # In-memory product sample data
│ │ ├── globals.css # Global styles + Syncfusion Tailwind 3 theme
│ │ ├── layout.tsx # Root layout
│ │ ├── page.tsx # Pivot Table page (client component)
│ │ └── 📁 api/
│ │ └── route.ts # API route: GET / POST / PUT / DELETE
│ ├── 📁 public/ # Static assets
│ ├── eslint.config.mjs
│ ├── next.config.ts
│ ├── package.json # Dependencies & scripts
│ ├── postcss.config.mjs
│ └── tsconfig.json
│
├── 📄 README.md # You are here
└── 📄 next-js-server.md # UG documentation source for this sample
⚙️ Installation & Setup
1. Clone the Repository
git clone https://github.com/SyncfusionExamples/syncfusion-react-pivot-with-nextjs-server.git
cd syncfusion-react-pivot-with-nextjs-server
2. Install Dependencies
Navigate to the nextjs_pivot/ folder and install the npm dependencies.
cd nextjs_pivot
npm install
Install the Syncfusion packages required by the Pivot Table:
npm install @syncfusion/ej2-react-pivotview @syncfusion/ej2-data @syncfusion/ej2-tailwind3-theme
Package descriptions:
- @syncfusion/ej2-react-pivotview – React Pivot Table component and supporting services.
- @syncfusion/ej2-data – Provides the
DataManager and Query classes used by the API route for paging.
- @syncfusion/ej2-tailwind3-theme – Tailwind 3 theme styles for the Pivot Table.
3. Set Up the Data Source
The data source lives inside the Next.js project at nextjs_pivot/app/data.ts. It contains an in-memory productDetails array that the API route uses to satisfy read and CRUD requests.
Create a file named data.ts inside the app/ folder and add the following code:
// filepath: nextjs_pivot/app/data.ts
import { IDataSet } from "@syncfusion/ej2-react-pivotview";
export const productDetails: IDataSet[] = [
{
"ProductID": 10001,
"ProductName": "Smartwatch",
"Category": "Electronics",
"MRP": 100.0,
"Discount": 1.02
},
{
"ProductID": 10002,
"ProductName": "Smartwatch",
"Category": "Accessories",
"MRP": 110.0,
"Discount": 1.12
},
{
"ProductID": 10003,
"ProductName": "Smartwatch",
"Category": "Home Appliances",
"MRP": 120.0,
"Discount": 1.22
},
{
"ProductID": 10004,
"ProductName": "Smartwatch",
"Category": "Gadgets",
"MRP": 130.0,
"Discount": 1.32
}
// ... (16 product records in the full sample)
];
| Field |
Data type |
Description |
ProductID |
number |
Unique product identifier (primary key) |
ProductName |
string |
Name of the product |
Category |
string |
Category to which the product belongs |
MRP |
number |
Maximum Retail Price of the product |
Discount |
number |
Discount value applied to the product |
📝 The Discount field is included for completeness and can be used as an additional value field in the Pivot Table. The minimal report in this sample summarizes only the MRP field, so Discount does not appear in dataSourceSettings.
⚠️ Persistence: productDetails is an in-memory array. Runtime CRUD changes are kept only in memory and are discarded when the server restarts. To persist changes, replace the in-memory array with file or database storage.
4. Configure the API Route
Next.js route handlers let you create server-side API endpoints directly within the application. These endpoints can process requests, retrieve data, and return the required response to the Pivot Table.
Create a new file named route.ts inside the app/api/ folder:
app
└─ api
└─ route.ts
Add the following GET, POST, PUT, and DELETE methods to route.ts. Each method handles a specific operation from the Pivot Table drill-through grid.
// filepath: nextjs_pivot/app/api/route.ts
import { NextResponse, NextRequest } from "next/server";
import { DataManager, Query } from '@syncfusion/ej2-data';
import { productDetails } from '../data';
// GET - Retrieve all data
export async function GET(request: NextRequest) {
const pivotStateParam = new URL(request.url).searchParams.get('pivotState');
if (!pivotStateParam) {
return NextResponse.json(
{ error: 'pivotState parameter is required', result: [], count: 0 },
{ status: 400 }
);
}
const pivotState = JSON.parse(decodeURIComponent(pivotStateParam));
const query = new Query();
// Execute query on data
let result: object[] = new DataManager(productDetails).executeLocal(query);
let count: number = result.length;
// Paging
if (pivotState.take && pivotState.take > 0) {
const skip = pivotState.skip || 0;
const take = pivotState.take;
query.page(skip / take + 1, take);
result = new DataManager(result).executeLocal(query);
}
return NextResponse.json({ result, count });
}
// POST - Create a new product
export async function POST(request: NextRequest) {
const body = await request.json();
if (body.action === 'add') {
const newProduct: any = {
ProductID: body.ProductID,
ProductName: body.ProductName,
Category: body.Category,
MRP: body.MRP,
Discount: body.Discount
};
productDetails.push(newProduct);
return NextResponse.json(newProduct, { status: 201 });
}
}
// PUT - Update an existing product
export async function PUT(request: NextRequest) {
const body = await request.json();
if (body.action === 'edit') {
const productIndex = productDetails.findIndex(u => u.ProductID === body.ProductID);
if (productIndex === -1) {
return NextResponse.json(
{ error: "Product not found" },
{ status: 404 }
);
}
productDetails[productIndex] = {
...productDetails[productIndex],
ProductID: body.ProductID || productDetails[productIndex].ProductID,
ProductName: body.ProductName || productDetails[productIndex].ProductName,
Category: body.Category || productDetails[productIndex].Category,
MRP: body.MRP || productDetails[productIndex].MRP,
Discount: body.Discount || productDetails[productIndex].Discount
};
return NextResponse.json(productDetails[productIndex]);
}
}
// DELETE - Delete a product
export async function DELETE(request: NextRequest) {
const body = await request.json();
if (body.action === 'delete') {
const productID = body[0].ProductID;
const productIndex = productDetails.findIndex(u => u.ProductID === productID);
if (productIndex === -1) {
return NextResponse.json(
{ error: "Product not found" },
{ status: 404 }
);
}
const deletedProduct = productDetails[productIndex];
productDetails.splice(productIndex, 1);
return NextResponse.json({ message: "Product deleted successfully" });
}
}
API method summary:
| Method |
Action payload |
Purpose |
GET |
(query: pivotState) |
Retrieve product records |
POST |
{ "action": "add", ... } |
Insert a new product |
PUT |
{ "action": "edit", "ProductID": ..., ... } |
Update an existing product (matched by ProductID) |
DELETE |
{ "action": "delete", [ { "ProductID": ... } ] } |
Delete a product by primary key |
5. Configure the Pivot Table
5.1 Add Pivot Table styles
After installing the packages, import the required Tailwind 3 theme styles for the Pivot Table. Open the app/globals.css file and add the following import:
/* filepath: nextjs_pivot/app/globals.css */
@import '../node_modules/@syncfusion/ej2-tailwind3-theme/styles/pivotview/index.css';
5.2 Add the Syncfusion React Pivot Table
Open the app/page.tsx file, remove any existing content if needed, and add the following code. The component is marked as a Client Component ('use client') because it uses React hooks, refs, and event handlers.