You need to sign in to do that
Don't have an account?
Indianajones
help me please with lwc
I created a lightning accordion with Account name and a lightning accordion section with Opportunity. I created a Tab for them and displayed it.
I need the following condition:
In case the component will be placed on the page with the account:
1. Only information about that account should be displayed.
2. Pagination, search, and filter by amount should be hidden.
how it look in tab:
apex code:
OpportunityController.apxc
thanks!
I need the following condition:
In case the component will be placed on the page with the account:
1. Only information about that account should be displayed.
2. Pagination, search, and filter by amount should be hidden.
how it look in tab:
apex code:
OpportunityController.apxc
public class OpportunityController { @AuraEnabled(cacheable=true) public static List<Account> getAcc( String searchKey) { string searchKeyword = '%' + searchKey + '%'; list<Account> accountListRecord = new list<Account>(); List<Opportunity> opportunityListRecord = new list<Opportunity>(); for(Account accObj : [SELECT Id, Name, (select id,Name,Amount,CreatedDate,CloseDate, AccountId from opportunities where StageName = 'Closed Won') FROM Account WHERE name LIKE : searchKeyword]){ accountListRecord.add(accObj); } // for(opportunity oppObj : [select id,Name,Amount,CreatedDate,CloseDate, AccountId from opportunity // WHERE Amount LIKE : searchKeyword]){ // opportunityListRecord.add(oppObj); // } if(accountListRecord.size() == 0){ throw new AuraHandledException('No Record Found..'); } return accountListRecord; } }LightningDatatableExample.html
<template> <lightning-card title="Lightning Datatable Example"> <div class="slds-m-around_medium"> <lightning-input type="search" onchange={handleKeyChange} class="slds-m-bottom_small" label="Search" value={searchKey}></lightning-input> <lightning-accordion allow-multiple-sections-open={multiple}> <template if:true={data}> <template for:each={data} for:item="acc"> <lightning-accordion-section name={acc.Name} label={acc.Name} key={acc.Id}> <lightning-card title="Opportunities"> <table class="slds-table slds-table_cell-buffer slds-table_bordered"> <thead> <tr class="slds-line-height_reset slds-text-title_caps"> <th class="slds-is-resizable" scope="col"> <div class="slds-truncate" title="Opportunity Name"> Opportunity Name </div> </th> <th class="slds-is-resizable" scope="col"> <div class="slds-truncate" title="Created Date"> Created Date </div> </th> <th class="slds-is-resizable" scope="col"> <div class="slds-truncate" title="Close Date"> Close Date </div> </th> <th class="slds-is-resizable" scope="col"> <div class="slds-truncate" title="Amount"> Amount </div> </th> </tr> </thead> <tbody> <template if:true={acc.Opportunities}> <template for:each={acc.Opportunities} for:item="opp"> <tr key={opp.Id}> <th scope="row" data-label="Name"> <div class="slds-truncate" title={opp.Name}>{opp.Name}</div> </th> <th scope="row" data-label="Account Number"> <div class="slds-truncate" title={opp.CreatedDate}>{opp.CreatedDate}</div> </th> <th scope="row" data-label="Industry"> <div class="slds-truncate" title={opp.CloseDate}>{opp.CloseDate}</div> </th> <th scope="row" data-label="Phone"> <div class="slds-truncate" title={opp.Amount}>{opp.Amount}</div> </th> </tr> </template> </template> </tbody> </table> <lightning-button variant="brand" label="Show me Opportunity Product" title="Primary action" onclick={handleClick} class="slds-m-left_x-small"></lightning-button> </lightning-card> </lightning-accordion-section> </template> </template> </lightning-accordion> </br> <lightning-layout horizontal-align="space"> <lightning-layout-item flexibility="auto"> <lightning-button label="Previous" icon-name="utility:chevronleft" onclick={previousHandler}> </lightning-button> </lightning-layout-item> <lightning-layout-item flexibility="auto"> Page {page} of {totalPage} </lightning-layout-item> <lightning-layout-item flexibility="auto"> <lightning-button label="Next" icon-name="utility:chevronright" icon-position="right" onclick={nextHandler}></lightning-button> </lightning-layout-item> </lightning-layout> </div> </lightning-card> </template>LightningDatatableExample.js
import { LightningElement, wire, api, track} from 'lwc'; import { refreshApex } from '@salesforce/apex'; import getAcc from '@salesforce/apex/OpportunityController.getAcc'; import getPreview from '@salesforce/apex/controllerTest.getPreview'; import { NavigationMixin } from 'lightning/navigation'; export default class LightningDatatableExample extends NavigationMixin(LightningElement) { @track value; @track error; @track data; @api searchKey = ''; result; @track page = 1; @track items = []; @track data = []; @track startingRecord = 1; @track endingRecord = 0; @track pageSize = 10; @track totalRecountCount = 0; @track totalPage = 0; @wire(getAcc, {searchKey: '$searchKey'}) wiredAccounts({ error, data }) { if (data) { this.items = data; this.totalRecountCount = data.length; this.totalPage = Math.ceil(this.totalRecountCount / this.pageSize); this.data = this.items.slice(0,this.pageSize); this.endingRecord = this.pageSize; this.error = undefined; } else if (error) { this.error = error; this.data = undefined; } } //clicking on previous button this method will be called previousHandler() { if (this.page > 1) { this.page = this.page - 1; //decrease page by 1 this.displayRecordPerPage(this.page); } } //clicking on next button this method will be called nextHandler() { if((this.page<this.totalPage) && this.page !== this.totalPage){ this.page = this.page + 1; //increase page by 1 this.displayRecordPerPage(this.page); } } //this method displays records page by page displayRecordPerPage(page){ this.startingRecord = ((page -1) * this.pageSize) ; this.endingRecord = (this.pageSize * page); this.endingRecord = (this.endingRecord > this.totalRecountCount) ? this.totalRecountCount : this.endingRecord; this.data = this.items.slice(this.startingRecord, this.endingRecord); this.startingRecord = this.startingRecord + 1; } handleKeyChange( event ) { this.searchKey = event.target.value; return refreshApex(this.result); } connectedCallback() { getPreview({ oppIds: this.recordId }) .then((result) => { this.contents = result; this.error = undefined; }) .catch((error) => { this.error = error; this.contents = undefined; }); } handleClick() { this[NavigationMixin.Navigate]({ type: 'standard__recordRelationshipPage', attributes: { recordId: '0065j00000CLKkxAAH', objectApiName: 'OpportunityLineItem', relationshipApiName: 'OpportunityLineItems', actionName: 'view' }, }); } }xml:
<?xml version="1.0" encoding="UTF-8"?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>52.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__AppPage</target> <target>lightning__HomePage</target> <target>lightning__RecordPage</target> <target>lightning__Tab</target> </targets> </LightningComponentBundle>help me please!
thanks!
Gace
Hey! Can you please share with me other tasks that you did in that salesforce course?