Hi guys :) I am new in programming and salesforce.
I want to get to the apex and take a name of click company can you tell me what schould I wite in field message = 'NAME OF CLICK COMPANY';
. When i am clicking on it I have just toast communicate from message.
I know the question is realy stiupid but please be tolerative I am new person in this crazy world :)
Example i found: Lightning Web Component: Can we catch rowclick event lightning-datatable just click
JS
import { wire, LightningElement } from 'lwc';
import getAllCompanys from '@salesforce/apex/StockMarketSharesWrapper.getAllCompanys';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class stockMarketShares extends LightningElement {
@wire(getAllCompanys, {}) companys;
columns = [{ label: 'Name', fieldName: 'Name' }, { label: 'Ticker', fieldName: 'Ticker' }]
title = 'Sample Title';
message = 'NAME OF CLICK COMPANY';
variant = 'error';
showCompanies = false;
showSearchResults() {
this.showCompanies = true;
}
handleClickRow(){
const evt = new ShowToastEvent({
title: this.title,
message: this.message,
variant: this.variant,
});
this.dispatchEvent(evt);
}
messageToast(event){
this.message = event.target.value;
}
}
APEX
public with sharing class StockMarketSharesWrapper {
@AuraEnabled(cacheable=true)
public static List<Wrapper> getAllCompanys(){
// Define the list
List<Wrapper> com = new List<Wrapper>();
// Create account sObjects
Wrapper w = new Wrapper();
w.Ticker = 'U';
w.Name = 'Unity Software Inc';
Wrapper w1 = new Wrapper();
w1.Ticker = 'UAL';
w1.Name = 'United Airlines Holdings, Inc.' ;
Wrapper w2 = new Wrapper();
w2.Ticker ='DAOOU' ;
w2.Name = 'Crypto 1 Acquisition Corp Unit';
Wrapper w3 = new Wrapper();
w3.Ticker = 'GLLIU';
w3.Name ='Globalink Investment Inc. Unit' ;
// Add accounts to the list
com.add(w);
com.add(w1);
com.add(w2);
com.add(w3);
return com;
}
public class Wrapper{
@AuraEnabled
public String Name {get; set;}
@AuraEnabled
public String Ticker {get; set;}
}
}
HTML
<lightning-datatable if:true={showCompanies} onclick={handleClickRow} hide-checkbox-column data={companys.data} columns={columns} key-field="Name"></lightning-datatable>
onclick
action forlightning-datatable
. developer.salesforce.com/docs/component-library/bundle/… .. instead you can useonrowaction
but again it gives entire row details.