function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul Yadav 272Rahul Yadav 272 

How to add data from List in <tbody>?

Hello Everyone,

I am trying to create a table. using simple SLDS data table. I have suceeessfully created the the table header in <thead >. but the Problem is with <tbody>.

I have create a apex class and wired it into js file to store the data in list. How do I add data in rows from that list into my table ?
Best Answer chosen by Rahul Yadav 272
ravi soniravi soni
Hi Rahul,
Try following Way and fix your problam.
let contacts=[];//This is the listOfContacts

<template if:true={contacts}>   
<template for:each={contacts.data} for:item="contact">
          <tr class="slds-hint-parent" key={contact.Id}>
            <td>
                  <div class="slds-truncate" title={contact.Name}>{contact.Name}</div>
            </td>
                <td>
                  <div class="slds-truncate" title={contact.Title}>{contact.Title}</div>
                </td>
                <td>
                  <div class="slds-truncate" title={contact.Phone}>{contact.Phone}</div>
                </td>
                <td>
                  <div class="slds-truncate" title={contact.Email}>{contact.Email}</div>
                </td>
               
              </tr>
            
        </template>   
     
        </template>
let me know if it helps you and marking it as best.
Thank You
 

All Answers

ravi soniravi soni
Hi Rahul,
Try following Way and fix your problam.
let contacts=[];//This is the listOfContacts

<template if:true={contacts}>   
<template for:each={contacts.data} for:item="contact">
          <tr class="slds-hint-parent" key={contact.Id}>
            <td>
                  <div class="slds-truncate" title={contact.Name}>{contact.Name}</div>
            </td>
                <td>
                  <div class="slds-truncate" title={contact.Title}>{contact.Title}</div>
                </td>
                <td>
                  <div class="slds-truncate" title={contact.Phone}>{contact.Phone}</div>
                </td>
                <td>
                  <div class="slds-truncate" title={contact.Email}>{contact.Email}</div>
                </td>
               
              </tr>
            
        </template>   
     
        </template>
let me know if it helps you and marking it as best.
Thank You
 
This was selected as the best answer
Rahul Yadav 272Rahul Yadav 272
Thanks Veer, that solved my problem