Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Thursday, May 29
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Extend lightning-datatable with file upload element in Lightning Web Component

    Extend lightning-datatable with file upload element in Lightning Web Component

    Dhanik Lal SahniBy Dhanik Lal SahniApril 17, 2020Updated:June 11, 202319 Comments2 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Extend lightning-datatable with file upload element in Lightning Web Component
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Recently we got a requirement to show list of account for getting status of uploaded document. If document is already uploaded  then list will show ‘No action required’ otherwise it will show file upload control.

    As per requirement we have to show list or table of records so we can extend standard lightning-datatable with conditional file upload control. Let us how we can extend lightning-datatable with file upload control.

    There is another blog https://salesforcecodex.com/2019/10/show-image-in-lightning-web-component-data-table/ which show how to add image control in lightning-datatable.

    We can use similar concept to add file upload control in lightning data table.

    Steps for extending  lightning-datatable

    1. Create component which show lightning-file-upload control
    2. Extend lightning-datatable with above component
    3. Use extended lightning-datatable to show requirement

    1. Create component which show lightning-file-upload control

    create LWC component which will show conditional lightning file upload. This condition is defined as @api property and its value is passed from lightning-datatable record. Basically we need to show file upload control for account which has not uploaded document. So we need current record’s document status.

    2. Extend lightning-datatable with above component

    Let us extend lightning-datatable so that it will add file upload control in one of column.  For extending any control we can use below code

    FileUploadDataTable extends LightningDatatable

    See comment in below code where we have created custom type from LightningDatatable.

     static customTypes = {   //it show that we are creating custom type
            fileUpload: {  // type of custom element
                template: documentUploadRender, // Which html will render
                typeAttributes: ['acceptedFileFormats','fileUploaded']  // attribute of custom type
            }
        };

    3. Use extended lightning-datatable to show requirement

    We have created new type by extending lightning-datatable. Let us see how we can use that component. For showing list in data table we have fetched account list.

    public class AccountController{
        @AuraEnabled
        public static List<Account> getPendingAccounts() {
            return [SELECT Id,Name, AccountNumber,IsDocumentComplete__c from Account];
        }
    }

    We have custom element fileUpload in lightning-datatable.  We can add attribute which we have created in above step. We have to set value in fileUploaded attribute of custom type. we can set value like fileUploaded:{fieldName: ‘IsDocumentComplete__c’} in column list.

    { label: 'Documents Upload', type: 'fileUpload', fieldName: 'Id', typeAttributes: { acceptedFileFormats: '.jpg,.jpeg,.pdf,.png',fileUploaded:{fieldName: 'IsDocumentComplete__c'} } }

    Let us show these records in new data table.

    Demo Page:

    Reference:

    https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/example

    http://salesforcecodex.com/2019/10/show-image-in-lightning-web-component-data-table/

    Related Posts:

    Generic DataTable in Lightning Web Component

    Single Row Selection in Lightning Datatable

    Update:

    Folder Structure for these components:

    SalesforceCodex file upload folder structure

    apex lightning component Lightning web component lwc salesforce
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleSalesforce Summer ’20 Release Postponed
    Next Article Extract Text From Image using Google Cloud Vision
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    View 19 Comments

    19 Comments

    1. Shubham on June 21, 2020 2:06 pm

      When we are using multiple columns in this data-table, the CSS is not auto handled. Header column size varies with content of the column. Can you please suggest how to control the CSS for the same.

      Reply
      • Dhanik Lal Sahni on June 23, 2020 12:16 am

        Hello Shubham,
        Please try with column-widths-mode property. Refer documentation https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/specificationhttps://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/specification for this.

        Thank You,
        Dhanik

        Reply
    2. Vignesh on July 5, 2020 2:23 pm

      HI,
      This issue coming while deploying file upload component.
      force-app\main\default\lwc\fileUploadDataTable\fileUploadDataTable.js LWC1011: Failed to resolve import “./documentUploadRender.html” from “fileUploadDataTable.js”. Please add “documentUploadRender.html” file to the component folder.

      Reply
      • Dhanik Lal Sahni on July 5, 2020 9:53 pm

        Hello Vignesh,
        You have to add documentUploadRender.html in fileUploadDataTable lwc component folder.

        Please try this. It will work.

        Thank You,
        Dhanik

        Reply
        • Dhanik Lal Sahni on July 5, 2020 10:11 pm

          I have also updated blog to show folder structure of all components.

          Thank You,
          Dhanik

          Reply
      • Nathan on July 29, 2020 12:50 am

        Hi Vignesh,

        This LWC1101 error happened to me and I ended up on this blog post. There seems to be an issue if the template filename (in your case ./documentUploadRender.html’) has more than one capital letter in camelcase. I ended up renaming my template to use all lowercase and it finally worked, for example ./progresstemplate.html – hope this helps. I spent almost an hour trying to call it progressBarTemplate.html. I will note that I think this will work with one uppercase letter, but not two. I couldn’t find any documentation on this issue so I wanted to add a comment on the top result.

        Reply
        • Dhanik Lal Sahni on July 31, 2020 9:43 pm

          Thank You Nathan for sharing info.

          Regards
          Dhanik

          Reply
    3. Venkatesh Ravichandran on September 5, 2020 12:23 pm

      Hi
      I have extended LWC datatable with a custom picklist column. It’s designed more like the above code. Only problem is that it is value update is uni direction. value changed in the picklist can be updated to the parent wrapper component’s this.dataRows using event. But if I change the this.dataRows in parent wrapper it’s not reflected in the extended picklist component even after doing this “this.dataRows = […this.dataRows]”.

      Reply
      • Dhanik Lal Sahni on September 5, 2020 1:07 pm

        Hello Venkatesh,

        Is dataRows variable is track property? Try using that. If it is not working, Let us connect to resolve your issue.

        Thank You,
        Dhanik

        Reply
      • Tamanna Chettiyar on June 30, 2022 5:55 pm

        Hi, was your issue resolved, I am also facing similiar issue. Can you help me to know how the issue was resolved?
        Thanks

        Reply
    4. Daniel on August 26, 2021 1:20 am

      I have a JSON and in this JSON I have a field that brings information in base64, I receive this value in a LWC, I need to transform this base64 value into an image according to the line it is in the datatable, can you help me with that?

      Reply
      • Dhanik Lal Sahni on August 30, 2021 10:38 pm

        Hello Daniel,
        Please check this link for converting base64 to image https://stackoverflow.com/questions/21227078/convert-base64-to-image-in-javascript-jquery

        I have also used same in another blogs View Files in Salesforce Lightning Community Portal and Capture Screen using Lightning Component

        Thank You,
        Dhanik

        Reply
    5. VIVEK on March 3, 2022 9:03 pm

      is there a way to do sorting on this ?

      Reply
      • Dhanik Lal Sahni on March 4, 2022 7:39 pm

        Yes Vivek, It can be done. You can see references from other blog Generic DataTable in Lightning Web Component

        Thank You,
        Dhanik

        Reply
    6. Sai Mohan on December 2, 2022 5:31 pm

      how to filter to display only parent related child records with this function

      Reply
      • Dhanik Lal Sahni on December 7, 2022 8:08 pm

        Hello Sai,

        You can try filtering in your apex or js.

        Thank You,
        Dhanik

        Reply
    7. Pingback: Data Table in Screen Flow - SalesforceCodex

    8. Krish on September 10, 2023 11:56 am

      Hi In this method is it possible to Change The Icons Dynamically Based on Rows Value

      Reply
      • Dhanik Lal Sahni on September 30, 2023 9:43 pm

        Yes Krish. It can be done.

        Thank You,
        Dhanik

        Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.