Monday, July 6, 2026

lwc - Paginated Data Table

📋 Paginated Data Table – Reusable Salesforce LWC

A reusable Lightning Web Component built on lightning-datatable that adds server-side sorting, pagination controls, row selection, loading states, and complete backend independence.

📖 Project Overview

Paginated Data Table is a fully controlled Salesforce Lightning Web Component that extends the standard lightning-datatable with enterprise-ready pagination and sorting capabilities.

Unlike traditional datatable implementations, this component never performs data retrieval itself. Instead, it simply renders the current page of data and communicates user actions back to the parent component using custom events. This makes it reusable with Apex, REST APIs, GraphQL services, wired adapters, or even static datasets.

The repository also includes a complete demo implementation powered by Apex using secure SOQL queries with WITH SECURITY_ENFORCED.

✨ Features

Feature Description
Server-side SortingFires sort events instead of sorting locally, allowing Apex or external services to perform sorting.
Pagination ControlsFirst, Previous, Next, Last navigation with configurable page size.
Row SelectionSupports standard lightning-datatable row selection events.
Row ActionsFully compatible with Edit, Delete and custom row action menus.
Loading StateBuilt-in spinner overlay while data is loading.
Error HandlingDisplays configurable error banners for backend failures.
Empty StateShows custom messages when no records are available.
Imperative APIProvides getSelectedRows() for parent components.
Backend AgnosticWorks with Apex, REST APIs, GraphQL or static arrays.

🏗 Component Architecture

Salesforce-Paginated-Data-Table-Reusable

📁 Project Structure

force-app
│
├── classes
│   ├── PaginatedTableController.cls
│   └── PaginatedTableControllerTest.cls
│
├── lwc
│   ├── paginatedDataTable
│   └── paginatedDataTableDemo
│
└── README.md

⚙️ Public API

Property Purpose
columnsColumn configuration for the datatable.
dataCurrent page records.
totalRecordsTotal number of available records.
pageSizeRecords displayed per page.
currentPageCurrent active page.
sortedByCurrent sorted field.
sortedDirectionAscending or Descending order.
isLoadingDisplays loading spinner.

🔄 User Workflow

Load Page
    │
    ▼
Parent Fetches Records
    │
    ▼
Render Current Page
    │
    ▼
User Sorts Column
    │
    ▼
Sort Event Fired
    │
    ▼
Parent Retrieves Data
    │
    ▼
Refresh Table

📡 Supported Events

  • sort — User changes column sorting.
  • pagechange — User navigates between pages.
  • rowselection — Selected rows change.
  • rowaction — Standard row actions.

🎯 Business Use Cases

  • Large Contact Lists
  • Opportunity Management
  • Account Dashboards
  • Service Case Management
  • Lead Administration
  • Experience Cloud Data Tables
  • External REST Data
  • Enterprise Reporting Dashboards

🔒 Security

  • Supports Salesforce CRUD/FLS.
  • Uses WITH SECURITY_ENFORCED in Apex demo.
  • Backend-independent architecture.
  • Compatible with enterprise security best practices.

🚀 Deployment

sf org login web --alias my-org

sf project deploy start \
--source-dir force-app \
--target-org my-org

sf apex run test \
--class-names PaginatedTableControllerTest

📌 Conclusion

Paginated Data Table is a lightweight, reusable, and enterprise-ready Lightning Web Component that extends the standard Salesforce datatable with server-side pagination, sorting, row selection, and configurable states. By separating presentation from data retrieval, it can be seamlessly integrated with Apex controllers, REST services, GraphQL APIs, or any custom backend while remaining highly reusable across Salesforce applications.

No comments:

Post a Comment