[SalesForce] Why is there no LWC lightning-list-view

There is an Aura lightning:listView, but presently not a LWC lightning-list-view. For most Aura components there is an LWC equivalent. That allows the composting composing of LWCs inside other LWCs which is a great way to leverage what has already been built rather than having to start from scratch.

Why no LWC in this case?

Best Answer

While looks there is no component which is very similar to aura version there is api thats of BETA quality.

There is a lightning/uiListApi module to get List views data and metadata in LWC. Note that as of today it is under BETA.

There is also a sample code in the trailhead recipe repo

import { LightningElement, wire } from 'lwc';
import { getListUi } from 'lightning/uiListApi';

import CONTACT_OBJECT from '@salesforce/schema/Contact';
import NAME_FIELD from '@salesforce/schema/Contact.Name';

export default class WireListView extends LightningElement {
 @wire(getListUi, {
    objectApiName: CONTACT_OBJECT,
    listViewApiName: 'All_Recipes_Contacts',
    sortBy: NAME_FIELD,
    pageSize: 10
})
listView;

 get contacts() {
    return this.listView.data.records.records;
 }
}

You can combine this with the lightning-datatable to get one similar to the list view.

Related Topic