Skip to content

Instantly share code, notes, and snippets.

@dhaniksahni
Created August 16, 2020 18:58
Show Gist options
  • Save dhaniksahni/1d11a2c52eb0546d88743278bde0351e to your computer and use it in GitHub Desktop.
Save dhaniksahni/1d11a2c52eb0546d88743278bde0351e to your computer and use it in GitHub Desktop.
LWC DataTable
<template>
<template if:true={contact}>
<lightning-datatable key-field="Id"
data={contact}
columns={columns}>
</lightning-datatable>
</template>
</template>
import { LightningElement, wire } from 'lwc';
import getContactList from '@salesforce/apex/ContactController.getContactList';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
const columns = [
{ label: 'First Name', fieldName: 'FirstName' },
{ label: 'Last Name', fieldName: 'LastName' },
{ label: 'Title', fieldName: 'Title' },
{ label: 'Phone', fieldName: 'Phone', type: 'phone' },
{ label: 'Email', fieldName: 'Email', type: 'email' }
];
export default class SingleSelectDatatable extends LightningElement {
error;
columns = columns;
contact=[];
connectedCallback()
{
getContactList()
.then((result,error) => {
if (result) {
this.contact=result;
} else if (error) {
console.error(error);
}
})
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>49.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__Tab</target>
</targets>
</LightningComponentBundle>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment