Sunday, May 20, 2018

Adding button and sorting columns in Lightning DataTable

Salesforce has launched Lightning:Datatable tag to display list of records in lightning components.

In this blog, I will share the code through which we can add a button in column and call javascript controller function on click of that button. Also I will share the code required to enable sorting on columns for datatable.

Use case: Display list of account records along with view button and onclick of that button call javascript controller function. Once the javascript controller function is invoked, you can open any other component or redirect user to account detail page as per requirement.

In order to add button, you have to specify input type as button and provide type attributes while specifying the columns.

label: 'Action',
type: 'button',
typeAttributes: {
iconName: 'utility:view',
label: 'View Record',
name: 'viewRecord',
disabled: false,
value: 'viewBtn'

you can use onrowaction event on lightning:datatable to call javascript controller function.

Below is sample code which includes sorting as well as button in one of the columns:

Below is snapshot:

Click here for  Lightning DataTable Demo .

Hope this will help!!!


  1. Indian Cyber Army’s most awaited internship is live now. Rush to register for Summer Internship 2018 on “ Ethical hacking” and book your seats before it runs out.Candidates have to get themselves registered to be a part of this Internship program. As career in ethical hacking is most in demand.

  2. Thanks for the information.It is really nice .In this age of Technology advancement, computer and information technology have not only brought convenience to citizens in modern life but also for policemen & various Government officials of the nation to fight cybercrime through various modus operandi. Indian Cyber Army has been dedicated in fighting cyber crime, striving to maintain law and order in cyberspace so as to ensure that everyone remains digitally safe.Read more:- Information Security

  3. thanks for sharing the more valuable information.
    Indian Cyber Army credibility in Ethical hacking training & Cybercrime investigation training is acknowledged across nation as we offer hands on practical knowledge and full assistance with basic as well as advanced level ethical hacking & cybercrime investigation courses. The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hacking/ cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure.Ethical hacking training ,
    Ethical hacking course

  4. This is awesome. Thanks for sharing!

  5. Thanks for such important information.keep up the good work.Searching for partners to romance typically through dating websites, apps or even social media can lure you into scammers trap pretending to be prospective companions. They play on emotional triggers to induce you to provide money, gifts or personal details.Read More : Dating scams

  6. It was a brilliant opportunity to visit this sort of site and I am cheerful to know, much obliged to you such a great amount for allowing us to have this open app development company chennai

  7. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
    Cyber Security Projects for Final Year

    JavaScript Training in Chennai

    Project Centers in Chennai

    JavaScript Training in Chennai