Skip to content

Instantly share code, notes, and snippets.

@jeremyvial
Created December 9, 2020 21:28
Show Gist options
  • Save jeremyvial/8e48dbb0e9f83f237d84756e8b8c8a16 to your computer and use it in GitHub Desktop.
Save jeremyvial/8e48dbb0e9f83f237d84756e8b8c8a16 to your computer and use it in GitHub Desktop.
LWC Challenge Component 2
public with sharing class CadeauControler {
@AuraEnabled(cacheable=true)
public static List<Cadeau__c> getCadeauxCreated() {
List <Cadeau__c> myCadeaux = new List <Cadeau__c>();
myCadeaux = [SELECT Id, Name, Price__c, CreatedDate, SecretKey__c, publicCible__c
FROM Cadeau__c
WHERE publicCible__c = 'Enfant' ];
return myCadeaux;
}
}
<template>
<lightning-card title="List of Christmas gifts for children" icon-name="standard:thanks">
<template if:true={cadeauList}>
<lightning-datatable data={cadeauList} columns={columns} key-field="Id">
</lightning-datatable>
</template>
</lightning-card>
</template>
import { LightningElement, track, wire } from 'lwc';
import getCadeau from '@salesforce/apex/CadeauControler.getCadeauxCreated';
export default class Component2 extends LightningElement {
@track record;
@track cadeauList;
@track columns = [{
label: 'Gift Name',
fieldName: 'Name',
type: 'text',
sortable: true
},
{
label: 'Price',
fieldName: 'Price__c',
type: 'currency',
sortable: true
},
{
label: 'Created Date',
fieldName: 'CreatedDate',
type: 'date',
sortable: true
},
{
label: 'Age of the child',
fieldName: 'publicCible__c',
type: 'String',
sortable: true
}
];
// ***********************************************
@wire(getCadeau, {})
wireAccount(result){
if (result.data) {
this.record = result.data;
this.cadeauList = result.data;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment