How do you configure and manage data display using the lightning-datatable component?
Answer
Basics: It is a base component for tables of records. You describe each column (label, fieldName, type) and pass rows as plain objects. Common types: text, number, currency, percent, date, date-local, boolean, url, email, phone, button, button-icon, action. key-field names a property whose value is unique per row (usually Id).
How it works: Setup: define columns, assign data from a wire or Apex call. Sorting: mark columns sortable: true, bind sorted-by, sorted-direction and onsort, and sort the array yourself (the table only emits the event). Selection: onrowselection, getSelectedRows(), selected-rows, max-row-selection. Row actions: a column { type: 'action', typeAttributes: { rowActions } } with onrowaction giving event.detail.action and event.detail.row. Inline editing: set editable: true on columns, handle onsave (event.detail.draftValues holds changed fields plus the key), save, then clear draft-values. Infinite scroll: enable-infinite-loading and onloadmore.
Advanced / deep dive: Data must be flat: relationship fields such as Account.Name are not read by with a dot path, so flatten rows (). Wire results are read-only, so clone before adding properties. Custom cell types are made by extending with and a template per type (useful for pickers or lookups, which are not native). Mutating a row in place will not re-render; reassign a new array. For very large data sets, page or load incrementally; rendering thousands of rows hurts performance. Edits are not saved automatically: you decide whether to call per row (LDS, runs triggers and validation) or Apex for bulk, and you should surface per-row problems with the attribute.