Agenda
In the previous blog, we see how can we select-deselect a checkbox using a master checkbox.
But Selecting and Deselecting checkboxes is not enough while working on any project we also need values to play with them.
Blog Details
The blog gives us a brief that how we select and unselect all checkboxes from the header checkbox.
What we are going to do
In this blog, we use a table to show the records with the checkbox for each record and a
header checkbox to select - unselect all records with a submit button.
And on that button click, we transfer the related record to the JS file of the component.
Requirements:
You need to have access to your org.
Should have installed the VS Code Installed in your system.
You should have some basic knowledge of Lightning Web Component.
You must have some proper records in your org to show data on the table.
A Little About Lightning Web Component(LWC)
Lightning Web Components is open-source, empowering you to
explore the source code, customize the behavior for your needs,
and build enterprise-ready web components on any platform,
not just Salesforce.
Lightning Web Component or LWC are custom HTML elements built using HTML and modern JavaScript.
We Basically work on ES6(ECMAScript 2015)
LWC uses core Web Components standards and delivers exceptional performance.
HINT: We can use Data - Attribute functionality to get the value of the selected checkboxes.
HTML Syntax:
Submit Button
<lightning-button class="slds-align_absolute-center" variant="brand"
value="Submit" label="Submit" onclick={handleSubmit}></lightning-button>
Row Checkboxes
<lightning-input type="checkbox" name="isSelect" data-pid={acc.Id} class="chkxBxs"></lightning-input>
"We use 'this.template.querySelectorAll()’ we use this method to look for the elements that
our component rendered. And get the value of the selected record’s".
To display the Records with a related checkbox follow this HTML:
We use the same code as discussed in the previous blog to display record’s on the layout.
Java Script:
handleSubmit() method handles the record list checkboxes according to the headerCheckbox
click event. ‘this.template.querySelectorAll('.chkBoxes)’.
Method fetch all checkboxes which contains the class named “chkBoxes”. And then,
We run the loop on the list of chkBoxes and get the Id of the selected Records.
Blog’s Conclusion:
So, the conclusion of the blog is that now we know how to connect a Lightning Web Component
(LWC) with the latest HTML data-attribute functionality and how to work with
‘this.template.querySelectorAll('.chkBoxes)’ and get familiar with checkboxes.
And play with Salesforce Data as per the needs.



Really informative
ReplyDelete