getListPreferences

Use this wire adapter to get the preferences for a list view.

Syntax 

1import { LightningElement, wire } from "lwc";
2import { getListPreferences } from "lightning/uiListsApi";
3import ACCOUNT_OBJECT from "@salesforce/schema/Account";
4
5export default class Example extends LightningElement {
6  @wire(getListPreferences, {
7    objectApiName: ACCOUNT_OBJECT,
8    listViewApiName:AllAccounts
9  })
10  propertyOrFunction;
11}

User Interface API Resource 

1GET /ui-api/list-preferences/${objectApiName}/${listViewApiName}

See Get List View Preferences.

Parameters 

Parameter NameTypeDescriptionRequired?
objectApiNameStringThe API name of a supported object.Yes
listViewApiNameStringThe API name of a list view, such as AllAccounts.Yes

Read the data that’s returned by the wire adapter using a property or function.

propertyOrFunction—A private property or function that receives the stream of data from the wire service.

  • If a property is decorated with @wire, the results are returned to the property’s data property or error property.
  • If a function is decorated with @wire, the results are returned in an object with a data property and an error property.

Returns 

Usage 

This code example fetches the preferences for a list view and displays the column widths for each displayed column.

1<!-- wireGetListPreferences.html -->
2<template>
3   <lightning-card title="wireGetListPreferences">
4       <template lwc:if={columnWidths}>
5           <div class="slds-m-around_medium">
6               <template for:each={columnWidths} for:item="col">
7                   <li key={col}>{col}</li>
8               </template>
9           </div>
10       </template>
11   </lightning-card>
12</template>
1// wireGetListPreferences.js
2import { LightningElement, wire } from "lwc";
3import { getListPreferences } from "lightning/uiListsApi";
4import ACCOUNT_OBJECT from "@salesforce/schema/Account";
5
6export default class GetListPrefs extends LightningElement {
7  error;
8  columnWidths;
9  @wire(getListPreferences, {
10    objectApiName: ACCOUNT_OBJECT.objectApiName,
11    listViewApiName: "AllAccounts",
12  })
13  listPrefs({ error, data }) {
14    if (data) {
15      this.columnWidths = Object.entries(data.columnWidths);
16      this.error = undefined;
17      debugger;
18    } else if (error) {
19      this.error = error;
20      this.columnWidths = undefined;
21      debugger;
22    }
23  }
24}

See Also