pagination-with-preserved-aggregates

Add server-side pagination with two-query backend pattern and consistent totals.

2|Updated May 10, 2026
One-click install
npx skills add https://github.com/freedomw1987/tree_monstor --skill pagination-with-preserved-aggregates
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pagination-with-preserved-aggregates
Source: https://github.com/freedomw1987/tree_monstor/tree/main/skills/software-development/pagination-with-preserved-aggregates
Command: npx skills add https://github.com/freedomw1987/tree_monstor --skill pagination-with-preserved-aggregates

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Adding server-side pagination to admin list pages often breaks summary statistics, page counts, and full-dataset Excel/CSV exports, because the same paginated query is incorrectly used to compute totals that should cover the entire filtered dataset.

Core Features & Use Cases

  • Two-query backend pattern: Separates paged row fetching from full-dataset aggregate queries to keep stats and exports accurate across all pagination states.
  • Frontend state management: Prevents double-fetch bugs and ensures stats cards read totals from the server, not the current page's row count.
  • Built-in smoke tests: Includes a reusable test template to verify the core invariant that totals remain consistent across page 1, page 2, full exports, and group-by modes.
  • Use case:适用于任何有列表页、统计卡片、导出功能的大数据量后台页面,比如订单管理、用户列表、审计日志、工时记录等,支持Prisma、Drizzle、Sequelize等所有主流ORM和Elysia、Express、Fastify等后端框架。

Quick Start

Use this skill to implement server-side pagination for your admin order list page while ensuring the total order count summary card and full-dataset Excel export always reflect the complete filtered dataset, not just the current page.

Frequently Asked Questions about pagination-with-preserved-aggregates

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do my summary statistics break when I add server-side pagination to admin list pages?

Summary statistics break because the same paginated query is incorrectly used to compute totals that should cover the entire filtered dataset. Separating paged row fetching from full-dataset aggregate queries keeps stats accurate across all pagination states.

How do I implement server-side pagination without breaking full-dataset Excel exports?

Implement a two-query backend pattern that separates paged row fetching from full-dataset aggregate queries. This ensures your Excel and CSV exports always reflect the complete filtered dataset rather than just the current page.

Does this pagination approach work with Prisma, Drizzle, and Sequelize?

Yes, this server-side pagination approach works with Prisma, Drizzle, and Sequelize, as well as backend frameworks like Elysia, Express, and Fastify. It applies to any data-table interface with summary cards and export functionality.

How do I prevent double-fetch bugs when managing frontend state for paginated data tables?

Prevent double-fetch bugs by implementing frontend state management that ensures stats cards read totals directly from the server, not the current page's row count. This avoids redundant API calls and keeps summary data consistent.

How can I test that pagination totals remain consistent across page views and exports?

Use the included reusable smoke test template to verify the core invariant that totals remain consistent across page 1, page 2, full exports, and group-by modes. This enforces that your summary statistics never drift during pagination.