I have a very simple LWC(just learning) I am trying to create something like a datatable(.net) or like the old visualforce page(PageBlockSection) like structure such as the related list and display it.
I can get data to display using the template however instead of just displaying it i want it displayed in a grid. Is there a very simple example anywhere?
Apex Class
public with sharing class ContactData {
@AuraEnabled(cacheable=true)
public static List<Contact> getContacts(String accId) {
return [SELECT Id, Name ,Email, Phone, Account.Name from Contact where AccountId = :accId];
}
}
HTML
<template>
<lightning-card title="Account Collection" icon-name="custom:custom14">
<div class="boarder">
<template if:true={myContacts.data}>
<ul class="slds-list_ordered">
<template for:each={myContacts.data} for:item="contact">
<li key={contact.Id}>
{contact.Name}
{contact.Email}
</li>
</template>
</ul>
</template>
</div>
JavaScript
import { LightningElement,api,wire } from 'lwc';
//Reads the Controller Class Get Contacts. Must Specify the file path - Class and Function returned.
import getContacts from '@salesforce/apex/ContactData.getContacts';
export default class RecordIdExample extends LightningElement {
//Passes a Record Id from the page to the Class.
@api recordId;
@wire(getContacts, {accId:'$recordId' })
//returns MyContacts as a variable that is then used in the HTML.
myContacts;
}