Lightning Web Components, Datatables & Interaction Design
A lightning-datatable is not a spreadsheet
The grid looked familiar; the workflow was undefined
A delivery team replaces a slow list page with a polished `lightning-datatable`. Users can sort columns, select rows and edit values inline, so the screen is described as a lightweight spreadsheet. In production, selection disappears after loading more rows, a multi-record save partly succeeds, totals change when the sort order changes and mobile users cannot operate the table. Each feature worked in isolation. The workflow did not.
The JSBC Labs position is that a `lightning-datatable` is not a spreadsheet. Salesforce provides a capable component for tabular data, including sorting, selection, row actions, infinite loading and inline editing for supported types. It does not define the business population, transaction boundary, validation policy, cross-page selection, recovery model or mobile alternative. Treat the datatable as a view and interaction surface over governed application services—not as a generic place to expose every field and let users manipulate records freely.
Design the task before the columns
Start with the decision or operation users must complete. A service manager triaging open cases needs severity, age, owner, next action and an explicit escalation command. A finance user correcting invoice references needs a controlled edit set, validation and an auditable save. Neither needs every available field. Column selection is therefore product design: each column must support recognition, comparison, action or required context.
Define a row contract with a stable key, display fields, action eligibility, version or freshness signal and the minimum data needed to complete the task. Salesforce requires `key-field` to associate rows correctly; that key must remain stable across sorting, filtering and incremental loads. Do not use array position or a mutable display value as identity. If the screen joins several objects, create a purposeful view model rather than leaking a convenient SOQL result into the browser.
The server owns the population
Client-side sorting and filtering are honest only when the browser already holds the complete population. Once the table uses pagination or infinite loading, sorting the loaded slice can present a locally ordered subset as if it were the result set. The server should own filter semantics, sort order, tie-breakers and page boundaries. Return a deterministic order and use stable cursor-based pagination where the data can change during a session.
Make scope visible to the user: ‘Open priority-one cases in EMEA’ is better than ‘Showing 50 rows’. Keep the filter and sort definition in a serialisable query state so it can be logged, bookmarked and reapplied after refresh. For bulk actions, store the intended selection model explicitly: selected IDs for a bounded set, or a query plus exclusions for ‘select all matching’. A checkbox in the header must never imply that unseen records are selected unless the service can prove and execute that meaning.
Load less data instead of testing the browser's patience
Salesforce's datatable performance guidance says browser rendering cost grows with rows, columns, inline editing and custom cell complexity. Salesforce testing found the best performance at a maximum of 1,000 rows and five columns, while also recommending that implementations load no more than 50 rows at a time. Those are useful reference points, not permission to render 1,000 heavy records in every experience; organisations must test realistic devices, data types and page composition.
Fetch only fields the view needs, initialise with a small page and load more through a bounded server request. Infinite loading requires a defined-height container so the component can determine its bottom and avoid repeated load events. Disable the loading trigger while a request is in flight, stop when the total is reached and protect against duplicate cursors. Measure time to usable rows, scroll responsiveness, save latency and browser memory—not just Apex execution time.
Inline editing needs an explicit commit contract
`draftValues` holds edited fields and record IDs until the user saves. The difficult decision is what Save means. Salesforce's UI API `updateRecord()` accepts one record at a time, so updating several records creates independent transactions. Salesforce recommends Apex when multiple records must be updated in one transaction. That distinction determines whether partial success is acceptable, how validation errors are reported and whether related updates must roll back together.
Choose deliberately. For independent corrections, per-record transactions can return precise successes and failures; preserve unsuccessful drafts and explain each row error. For a business action that must be atomic, send a typed command to Apex, validate the whole set and commit once. Do not pass arbitrary field maps into a generic update method. Enforce object, field and record access on the server, apply business rules and reject stale edits when another user has changed the record since it was loaded.
Refresh the right caches—and keep failures actionable
After an Apex save, the visible rows and other components can disagree unless cache ownership is handled. Salesforce directs developers to use `refreshApex()` for data provisioned through an Apex wire, and `notifyRecordUpdateAvailable(recordIds)` when records changed outside Lightning Data Service and relevant LDS wires must refresh. Clearing drafts before the confirmed save and refresh can make a failed edit appear successful, so sequence the state transition carefully.
Return structured errors with record ID, field where applicable, safe user message and a correlation reference for support. `lightning-datatable` can display row- and table-level errors, including field messages for editable columns. Use that capability rather than a single toast saying ‘Some records failed’. Keep successful rows committed, failed drafts intact when partial success is allowed and a retry button idempotent. A grid is trustworthy when users can see exactly what changed and what still requires attention.
Custom cells inherit accessibility and performance obligations
A custom type is sometimes necessary for badges, compound content or purpose-built actions, but every nested component expands DOM work and interaction complexity. Salesforce recommends simple custom cells with few nesting levels. The default bare layout for custom types does not provide the same accessibility and keyboard-navigation support as the standard layout; setting `standardCellLayout: true` helps custom editable types participate in established table behaviour.
Test navigation mode and action mode with the keyboard, not only mouse clicks. Verify focus order, accessible names, errors, disabled states, resizing and high zoom. Salesforce documents that `lightning-datatable` is not supported on mobile devices, and responsive desktop emulation does not create a mobile contract. If the use case includes phones, design a card, list or task-specific mobile experience with the same service layer instead of shrinking the desktop grid until it technically fits.
Release a data workflow—not a reusable table wrapper
Generic wrappers often accumulate dynamic columns, filters, row actions, inline edit, export and selection until no team can predict their behaviour. Reuse the stable primitives—query state, cursor protocol, error model, permission checks and design tokens—but keep task-specific columns and actions close to the business workflow. A smaller component with a clear contract is easier to test than one universal grid configured by hundreds of flags.
Before release, test empty and large populations, permission differences, stale records, validation failures, partial saves, concurrent edits, slow networks, cursor boundaries, keyboard use and the mobile alternative. Instrument load-more failures, save outcomes and abandoned drafts. The component is successful when users complete governed work accurately and quickly, not when the screen resembles Excel. `lightning-datatable` supplies strong table mechanics; architecture must supply the boundaries that make those mechanics safe.
Official references
- Salesforce Developers — lightning-datatable Component Reference
- Salesforce Developers — Improve Datatable Performance
- Salesforce Developers — Display Data in a Table with Inline Editing
- Salesforce Developers — Data Guidelines
- Salesforce Developers — notifyRecordUpdateAvailable(recordIds)
- Salesforce Developers — Create Custom Data Types
- Salesforce Developers — Customize Data Type Layout and Styles
- Salesforce Developers — Datatable Accessibility
- Salesforce Developers — GraphQL Pagination with lightning-datatable
- Salesforce Developers — Runtime Behavior Anti-Patterns in Lightning Web Components