{"id":2428,"date":"2026-10-24T09:00:00","date_gmt":"2026-10-24T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/"},"modified":"2026-11-15T11:29:49","modified_gmt":"2026-11-15T05:59:49","slug":"lwc-datatable-advanced","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/","title":{"rendered":"lightning-datatable Advanced: Inline Edit, Sorting and Custom Types"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>lightning-datatable<\/code> component does far more than show rows. It handles sorting, selection, inline editing, row actions and infinite loading, all through column configuration rather than markup. So a full featured table takes one tag and a JavaScript array.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/lightning-base-components-overview\/\">Lightning Base Components<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/call-apex-from-lwc-wire-imperative\/\">calling Apex from LWC<\/a>. We will build a course table for Bright Path Tutors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is lightning-datatable?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>lightning-datatable<\/code> component renders a table from an array of data and an array of column definitions. Each column object says what to show, how to format it and whether users can edit it. The component handles the rest.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a spreadsheet template. You define the headers and the cell types once, then pour the rows in. The grid takes care of alignment, sorting and editing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why lightning-datatable Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hand built tables in Salesforce age badly. They miss keyboard navigation, screen reader support and the hover and focus states users expect.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using <code>lightning-datatable<\/code> gives all of that for free. More importantly, inline editing with bulk save is hard to write correctly, and the component already does it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How lightning-datatable Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Data and columns go in, and events come back out when users act.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-1-1024x640.png\" alt=\"lightning-datatable diagram showing the inline edit and save path\" class=\"wp-image-2426\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How an inline edit reaches the database.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Column Types<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const COLUMNS = [\n    { label: 'Course', fieldName: 'Name', sortable: true },\n    { label: 'Fee', fieldName: 'Fee__c', type: 'currency', editable: true },\n    { label: 'Starts', fieldName: 'Start_Date__c', type: 'date' },\n    { label: 'Online', fieldName: 'Is_Online__c', type: 'boolean' },\n    { label: 'Level', fieldName: 'Level__c', sortable: true }\n];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Supported types include text, number, currency, percent, date, email, phone, url, boolean, button and action.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Making a Link Column<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A common need is linking to the record. Build the URL in Apex or JavaScript and use the url type.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    label: 'Course',\n    fieldName: 'recordLink',\n    type: 'url',\n    typeAttributes: { label: { fieldName: 'Name' }, target: '_self' }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>this.rows = data.map(row =&gt; ({\n    ...row,\n    recordLink: '\/' + row.Id\n}));<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Sorting<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;lightning-datatable\n    key-field=\"Id\"\n    data={rows}\n    columns={columns}\n    sorted-by={sortedBy}\n    sorted-direction={sortDirection}\n    onsort={handleSort}&gt;\n&lt;\/lightning-datatable&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>handleSort(event) {\n    const { fieldName, sortDirection } = event.detail;\n    const cloned = [...this.rows];\n    cloned.sort((a, b) =&gt; {\n        const x = a[fieldName] ?? '';\n        const y = b[fieldName] ?? '';\n        return sortDirection === 'asc'\n            ? (x &gt; y ? 1 : x &lt; y ? -1 : 0)\n            : (x &lt; y ? 1 : x &gt; y ? -1 : 0);\n    });\n    this.rows = cloned;\n    this.sortedBy = fieldName;\n    this.sortDirection = sortDirection;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The component does not sort for you. It raises the event and you reorder the array.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Inline Editing and Bulk Save<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;lightning-datatable\n    key-field=\"Id\"\n    data={rows}\n    columns={columns}\n    draft-values={draftValues}\n    onsave={handleSave}&gt;\n&lt;\/lightning-datatable&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import { updateRecord } from 'lightning\/uiRecordApi';\nimport { refreshApex } from '@salesforce\/apex';\n\nasync handleSave(event) {\n    const records = event.detail.draftValues.map(draft =&gt; ({ fields: { ...draft } }));\n    try {\n        await Promise.all(records.map(rec =&gt; updateRecord(rec)));\n        this.draftValues = [];\n        await refreshApex(this.wiredResult);\n    } catch (error) {\n        console.error(error);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each draft already contains the Id, because <code>key-field<\/code> told the component which field identifies a row.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Datatable Attribute Reference<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This table lists the attributes you will set most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Attribute<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td>key-field<\/td><td>Unique field per row, required<\/td><\/tr><tr><td>data<\/td><td>The array of rows<\/td><\/tr><tr><td>columns<\/td><td>The column definitions<\/td><\/tr><tr><td>hide-checkbox-column<\/td><td>Removes row selection<\/td><\/tr><tr><td>max-row-selection<\/td><td>Limits how many rows can be ticked<\/td><\/tr><tr><td>draft-values<\/td><td>Holds pending inline edits<\/td><\/tr><tr><td>enable-infinite-loading<\/td><td>Turns on load more<\/td><\/tr><tr><td>load-more-offset<\/td><td>How close to the end before loading<\/td><\/tr><tr><td>is-loading<\/td><td>Shows the loading indicator<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Infinite Loading in lightning-datatable<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For large result sets, load a page at a time rather than everything at once.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;lightning-datatable\n    key-field=\"Id\"\n    data={rows}\n    columns={columns}\n    enable-infinite-loading\n    load-more-offset=\"20\"\n    onloadmore={loadMore}&gt;\n&lt;\/lightning-datatable&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>async loadMore(event) {\n    const target = event.target;\n    target.isLoading = true;\n    const next = await getCourses({ offset: this.rows.length });\n    this.rows = [...this.rows, ...next];\n    target.isLoading = false;\n    if (next.length === 0) { target.enableInfiniteLoading = false; }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Turning off infinite loading at the end stops the component asking forever. Because each page is a separate Apex call, the first paint is fast and the user scrolls into the rest. So a table of several thousand rows stays responsive, while loading everything up front would freeze the browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Custom Column Types for lightning-datatable<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When no built-in type fits, extend the component itself.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import LightningDatatable from 'lightning\/datatable';\nimport levelBadge from '.\/levelBadge.html';\n\nexport default class CourseDatatable extends LightningDatatable {\n    static customTypes = {\n        levelBadge: {\n            template: levelBadge,\n            standardCellLayout: true,\n            typeAttributes: ['level']\n        }\n    };\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n    &lt;lightning-badge label={typeAttributes.level}&gt;&lt;\/lightning-badge&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You then use <code>c-course-datatable<\/code> in place of the standard tag, with a column of type <code>levelBadge<\/code>. Because your class extends the real component, every other feature still works. So you keep sorting, selection and inline editing while adding the one cell style you needed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Datatable vs Tree Grid<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These two look similar. This table separates them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Datatable<\/th><th>Tree grid<\/th><\/tr><\/thead><tbody><tr><td>Row structure<\/td><td>Flat<\/td><td>Parent and child<\/td><\/tr><tr><td>Expand and collapse<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Inline editing<\/td><td>Full<\/td><td>Limited<\/td><\/tr><tr><td>Large data<\/td><td>Handles well<\/td><td>Heavier<\/td><\/tr><tr><td>Typical use<\/td><td>Record lists<\/td><td>Hierarchies<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-2-1024x640.png\" alt=\"lightning-datatable compared with lightning-tree-grid\" class=\"wp-image-2427\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Datatable compared with tree grid.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use a datatable for a list. Use a tree grid only when rows genuinely nest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real lightning-datatable Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bright Path wants a course table where counsellors edit fees inline, sort by any column and open the record in one click.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Apex<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseTableCtrl {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Course__c&gt; getCourses(Integer offset) {\n        Integer skip = (offset == null) ? 0 : offset;\n        return [SELECT Id, Name, Fee__c, Level__c, Start_Date__c\n                FROM Course__c\n                ORDER BY Name\n                LIMIT 50 OFFSET :skip];\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: The Component<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement, wire } from 'lwc';\nimport getCourses from '@salesforce\/apex\/CourseTableCtrl.getCourses';\n\nconst COLUMNS = [\n    { label: 'Course', fieldName: 'link', type: 'url',\n      typeAttributes: { label: { fieldName: 'Name' } }, sortable: true },\n    { label: 'Fee', fieldName: 'Fee__c', type: 'currency', editable: true },\n    { label: 'Level', fieldName: 'Level__c', sortable: true }\n];\n\nexport default class CourseTable extends LightningElement {\n    columns = COLUMNS;\n    rows = [];\n    draftValues = [];\n    wiredResult;\n\n    @wire(getCourses, { offset: 0 })\n    wired(result) {\n        this.wiredResult = result;\n        if (result.data) {\n            this.rows = result.data.map(r =&gt; ({ ...r, link: '\/' + r.Id }));\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Keeping the wired result in a property is what lets you call <code>refreshApex<\/code> later.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Check the Behaviour<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">These are the features the table now has.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>How it was enabled<\/th><\/tr><\/thead><tbody><tr><td>Clickable name<\/td><td>url column type with typeAttributes<\/td><\/tr><tr><td>Editable fee<\/td><td>editable true on the column<\/td><\/tr><tr><td>Sorting<\/td><td>sortable true plus an onsort handler<\/td><\/tr><tr><td>Bulk save<\/td><td>draft-values and onsave<\/td><\/tr><tr><td>Refresh after save<\/td><td>refreshApex on the stored wire result<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with lightning-datatable<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Leaving out key-field, which breaks row tracking and editing.<\/li>\n\n<li>Expecting the component to sort for you, when it only raises the event.<\/li>\n\n<li>Mutating the rows array directly instead of replacing it.<\/li>\n\n<li>Loading thousands of rows at once rather than paging.<\/li>\n\n<li>Forgetting refreshApex, so saved values do not reappear.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for lightning-datatable<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always set key-field to Id.<\/li>\n\n<li>Replace arrays rather than pushing into them, so reactivity fires.<\/li>\n\n<li>Use infinite loading beyond a few hundred rows.<\/li>\n\n<li>Keep editable columns to the few that users actually change.<\/li>\n\n<li>Clear draft values after a successful save.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Build a table with three columns where one is editable, and clear the drafts after save. Hint: the draft values already include the record Id.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked lightning-datatable Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These lightning-datatable questions appear in most LWC interviews.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic lightning-datatable Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is lightning-datatable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The lightning-datatable component renders a table from a data array and a column definition array, with sorting, selection and editing built in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What does key-field do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It names the unique field per row, usually Id, so lightning-datatable can track rows across edits and sorts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How do you make a column editable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set editable to true in that column definition, and a pencil icon then appears on hover.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Which event fires when a user saves inline edits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The onsave event fires, and its detail holds the draft values the user changed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you remove the checkbox column?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the hide-checkbox-column attribute to the tag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What column types are available?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The lightning-datatable types include text, number, currency, percent, date, email, phone, url, boolean, button and action.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: How do you add a menu to each row?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a column of type action with rowActions, then handle onrowaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: Does the component sort automatically?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. It fires onsort and you reorder the array yourself.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Intermediate lightning-datatable Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you link to a record from a cell?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add a url field to each row in JavaScript, then use a url column with typeAttributes for the label.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: What is refreshApex used for?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It re-runs a wired Apex call, so the table shows fresh data after a save.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: Why must you store the wire result?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because refreshApex needs the whole result object, not just the data array.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: How does infinite loading work?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set enable-infinite-loading, handle onloadmore, fetch the next page and append it to the array.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: How do you stop infinite loading at the end?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set enableInfiniteLoading to false on the target once an empty page comes back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: Why replace the array instead of pushing to it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because reactivity watches the reference. Pushing mutates in place, so the component may not re-render.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: How do you limit row selection?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set max-row-selection to the number of rows allowed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Do inline edits respect validation rules?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. The update goes through normal DML, so rules, triggers and flows all run.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced lightning-datatable Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: How do you create a custom column type?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Extend LightningDatatable, declare customTypes with a template, then use your component instead of the standard tag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: Scenario: a table of 10,000 rows is unusable. What do you change?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Page the data in Apex with LIMIT and OFFSET, use infinite loading and reduce the number of columns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: What is the problem with large OFFSET values?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SOQL caps OFFSET at 2,000. So for deep paging use a key-set filter on the last Id or sort value instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: Scenario: saved edits vanish after refresh. Why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The draft values were not cleared or refreshApex was not called, so the old cached data came back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: How do you show a toast after a bulk save?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Handle onsave, await the updates, then dispatch a ShowToastEvent with the count.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: How does the component handle field level security?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It renders whatever your Apex returns. So enforce security in the query, because the table does not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: How do you test a datatable component?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With Jest, asserting on the rendered rows and firing the events the component listens for.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: When should you not use lightning-datatable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When rows nest, when the design is far from a grid, or when users need rich editing that the cell types do not cover.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Can lightning-datatable show a row number?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, with the show-row-number-column attribute. So long tables become easier to discuss with a colleague.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: How do you pre-select rows?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set selected-rows to an array of key field values. Then the component ticks those rows on load.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: Does lightning-datatable work on mobile?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, and it scrolls horizontally on small screens. However, fewer columns make it far more usable on a phone.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: Scenario: currency shows the wrong symbol. What do you check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The user locale and the org currency settings, since the column formats by user locale rather than by record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: How do you export the rows to CSV?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build the CSV string in JavaScript from your data array and trigger a download. The component has no export of its own.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/component-library\/bundle\/lightning-datatable\/documentation\" target=\"_blank\" rel=\"noopener noreferrer\">Component Reference: lightning-datatable<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/lwc\/guide\/data-table-custom-types.html\" target=\"_blank\" rel=\"noopener noreferrer\">LWC Guide: Create a Custom Data Type<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/lwc\/guide\/apex-result-caching.html\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Reference: refreshApex<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>lightning-datatable builds a full table from data and column arrays.<\/li>\n\n<li>key-field is required and should be Id.<\/li>\n\n<li>Sorting fires an event, but you reorder the array.<\/li>\n\n<li>Inline edits arrive as draft values on the onsave event.<\/li>\n\n<li>Use infinite loading and paging for large result sets.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we handle user input properly with <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-form-validation\/\">LWC Form Validation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The lightning-datatable component does far more than show rows. It handles sorting, selection, inline editing, row actions and infinite loading, all through column configuration&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2425,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[245,8,96],"tags":[68,113],"swapz_series":[],"class_list":["post-2428","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lightning-web-components","category-salesforce","category-salesforce-developer","tag-advanced","tag-lwc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>lightning-datatable Advanced Features in LWC<\/title>\n<meta name=\"description\" content=\"Learn lightning-datatable advanced features: inline editing, sorting, row actions, infinite loading and custom column types, with interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"lightning-datatable Advanced Features in LWC\" \/>\n<meta property=\"og:description\" content=\"Learn lightning-datatable advanced features: inline editing, sorting, row actions, infinite loading and custom column types, with interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-24T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T05:59:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"lightning-datatable Advanced: Inline Edit, Sorting and Custom Types\",\"datePublished\":\"2026-10-24T03:30:00+00:00\",\"dateModified\":\"2026-11-15T05:59:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/\"},\"wordCount\":1549,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-datatable-advanced-featured.png\",\"keywords\":[\"Advanced\",\"LWC\"],\"articleSection\":[\"Lightning Web Components\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/\",\"name\":\"lightning-datatable Advanced Features in LWC\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-datatable-advanced-featured.png\",\"datePublished\":\"2026-10-24T03:30:00+00:00\",\"dateModified\":\"2026-11-15T05:59:49+00:00\",\"description\":\"Learn lightning-datatable advanced features: inline editing, sorting, row actions, infinite loading and custom column types, with interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-datatable-advanced-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-datatable-advanced-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"lightning-datatable featured image: code editor card with column definition\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-datatable-advanced\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"lightning-datatable Advanced: Inline Edit, Sorting and Custom Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"lightning-datatable Advanced Features in LWC","description":"Learn lightning-datatable advanced features: inline editing, sorting, row actions, infinite loading and custom column types, with interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/","og_locale":"en_US","og_type":"article","og_title":"lightning-datatable Advanced Features in LWC","og_description":"Learn lightning-datatable advanced features: inline editing, sorting, row actions, infinite loading and custom column types, with interview questions.","og_url":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-24T03:30:00+00:00","article_modified_time":"2026-11-15T05:59:49+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"lightning-datatable Advanced: Inline Edit, Sorting and Custom Types","datePublished":"2026-10-24T03:30:00+00:00","dateModified":"2026-11-15T05:59:49+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/"},"wordCount":1549,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-featured.png","keywords":["Advanced","LWC"],"articleSection":["Lightning Web Components","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/","url":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/","name":"lightning-datatable Advanced Features in LWC","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-featured.png","datePublished":"2026-10-24T03:30:00+00:00","dateModified":"2026-11-15T05:59:49+00:00","description":"Learn lightning-datatable advanced features: inline editing, sorting, row actions, infinite loading and custom column types, with interview questions.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-datatable-advanced-featured.png","width":2400,"height":1260,"caption":"lightning-datatable featured image: code editor card with column definition"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-datatable-advanced\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"lightning-datatable Advanced: Inline Edit, Sorting and Custom Types"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=2428"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2428\/revisions"}],"predecessor-version":[{"id":3196,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2428\/revisions\/3196"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2425"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2428"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}