In this video you will learn how to create List Builder in Lightning Web Component. We will use the Lightning Design System to create the UI for this.
Please check the reference links below :
Official Documentation : https://www.lightningdesignsystem.com/components/list-builder/
Wire list of Accounts :
https://www.salesforcebolt.com/2021/06/wire-apex-with-property-and-functions-lwc.html
Create Custom Modal :
https://www.salesforcebolt.com/2021/06/ep-25-custom-modal-popup-in-lwc-lwc.html
#ListBuilder #LWC #salesforce
Please check complete code below :
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | <template> <template if:true={showModal}> <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open" > <div class="slds-modal__container"> <!-- Header Start --> <header class="slds-modal__header"> <lightning-button-icon class="slds-modal__close" title="Close" icon-name="utility:close" icon-class="slds-button_icon-inverse" onclick={closeModal} ></lightning-button-icon> <h2 id="id-of-modalheader-h2" class="slds-text-heading_large"> Select Accounts </h2> <p class="slds-var-m-top_x-small">Select data from the list</p> </header> <!-- Header End --> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1" > <template if:true={showSpinner}> <lightning-spinner alternative-text="Loading" variant="brand" size="medium" > </lightning-spinner> </template> <div class="slds-grid slds-grid_vertical"> <div class="slds-scrollable slds-grow"> <div class="slds-scrollable_none"> <table aria-multiselectable="true" class=" slds-table slds-no-row-hover slds-table_bordered slds-table_fixed-layout slds-table_resizable-cols " role="grid" > <thead> <tr class="slds-line-height_reset"> <th class="" scope="col" style="width: 3.75rem"></th> <th aria-label="Name" aria-sort="none" class="slds-is-resizable slds-is-sortable" scope="col" > <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="-1" > <span class="slds-assistive-text">Sort by: </span> <div class=" slds-grid slds-grid_vertical-align-center slds-has-flexi-truncate " > <span class="slds-truncate" title="Name" >Account Name</span > <span class=" slds-icon_container slds-icon-utility-arrowdown " > </span> </div> </a> <div class="slds-resizable"> <input type="range" aria-label="Name column width" class="slds-resizable__input slds-assistive-text" id="cell-resize-handle-65" max="1000" min="20" tabindex="-1" /> <span class="slds-resizable__handle"> <span class="slds-resizable__divider"></span> </span> </div> </th> <th aria-label="Phone" aria-sort="none" class="slds-is-resizable slds-is-sortable" scope="col" > <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="-1" > <span class="slds-assistive-text">Sort by: </span> <div class=" slds-grid slds-grid_vertical-align-center slds-has-flexi-truncate " > <span class="slds-truncate" title="Phone" >Phone</span > <span class=" slds-icon_container slds-icon-utility-arrowdown " > </span> </div> </a> </th> </tr> </thead> <tbody> <template for:each={accounts} for:item="acc"> <tr key={acc.Id} aria-selected="false" class="slds-hint-parent" > <td class="slds-text-align_right" role="gridcell"> <lightning-input type="checkbox-button" label="select" variant="label-hidden" onchange={handleCheck} name={acc.Id} ></lightning-input> </td> <td role="gridcell"> <div class="slds-cell-wrap" title="Name"> {acc.Name} </div> </td> <td role="gridcell"> <div class="slds-cell-wrap" title="Phone"> {acc.Phone} </div> </td> </tr> </template> </tbody> </table> </div> </div> </div> </div> <footer class="slds-modal__footer"> <template if:true={message}> <span class="slds-text-color_error">{message}</span> </template> <lightning-button variant="brand-outline" label="Cancel" onclick={closeModal} title="Cancel" class="slds-var-m-left_x-small" ></lightning-button> <lightning-button variant="brand" label="Next" onclick={applyActions} title="Next" class="slds-var-m-left_x-small" ></lightning-button> </footer> </div> </section> <div class="slds-backdrop slds-backdrop_open"></div> </template> </template> |
JS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import { LightningElement, api, wire, track } from "lwc"; import { ShowToastEvent } from "lightning/platformShowToastEvent"; import getAccountList from "@salesforce/apex/AccountController.getAccList"; export default class ListBuilderComponent extends LightningElement { @track loaded; @api selectedAccounts = []; @api selectedAccsString; message; accounts; showModal = true; @api show() { this.showModal = true; } @wire(getAccountList) wiredAccounts({ error, data }) { if (data) { this.accounts = data; this.error = undefined; } else if (error) { this.error = error; this.accounts = undefined; } } handleCheck(event) { console.log("###Current Target : " + event.currentTarget.name); } closeModal() { this.showModal = false; } } |
Output
Checkout complete video tutorial below
0 Comments