How to wrap text in a table in LWC in Salesforce?

Sample code:



    <div class="slds-box slds-theme_default">
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered">
                    <th scope="col">
                        <div class="slds-truncate" title="Account Name">Name</div>
                    <th class="" scope="col">
                        <div class="slds-truncate" title="Account Industry">Industry</div>
                    <th class="" scope="col">
                        <div class="slds-truncate" title="Account Type">Type</div>
                    <th class="" scope="col">
                        <div class="slds-truncate" title="Account Number">Account Number</div>
                    <th class="" scope="col">
                        <div class="slds-truncate" title="Site">Site</div>
                    <th style="width:250px;">
                        <div class="slds-truncate" title="Description">Description</div>
                <template for:each={accounts} for:item="acc">
                    <tr key={acc.Id}>
                        <td class="slds-cell-wrap">{acc.Description}</td>


import { LightningElement, wire, track } from 'lwc';
import fetchAccounts from '@salesforce/apex/ExampleController.fetchAccounts';

export default class Example extends LightningElement {

    @track accounts;
    @wire( fetchAccounts ) 
    caseRecord({ error, data }) { 
        if ( data ) { 
            this.accounts = data; 
        } else if ( error )
            console.log( 'Error is ' + JSON.stringify( error ) );


JavaScript meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">

Apex Class:

public with sharing class ExampleController {

    public static List < Account > fetchAccounts() {

        return [ SELECT Id, Name, Industry, Type, AccountNumber, Site, Description FROM Account LIMIT 10 ];



No comments:

Post a Comment