function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Oleg NikitchukOleg Nikitchuk 

Lightnignt:combobox how to get options without hardcoding them?

Hi All!

I am trying to get the options without hard-coding them. Right now, I have a filter for Position__c, this filter is Status__c and there are 3 possible variants for status: all, opened, closed. While I've made it possible to make it work, but what if a user decides to add more statuses. That will make me code it again, so i want to write a method that will allow user add it automatically.

Here's my code: 
HTML:
<template> <div class="slds-box slds-theme_default"> <div class="slds-text-color_inverse slds-text-heading_large" style="padding:0.5rem;background:#16325c"> Positions </div> <div style="width:200px; padding:0.5rem;"> <lightning-combobox name="filter" label="Status" value={selectedFilter} variant="label-hidden" options={options} onchange={handleChange} placeholder="Select Status to filter"></lightning-combobox> </div> <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped"> <thead> <tr class="slds-line-height_reset"> <th class="" scope="col">Position Name</th> <th class="" scope="col">Status</th> <th class="" scope="col">Opening Date</th> <th class="" scope="col">Closing Date</th> <th class="" scope="col">Minimum Salary</th> <th class="" scope="col">Maximum Salary</th> </tr> </thead> <tbody> <template for:each={positions} for:item="pos" for:index="index"> <tr key={pos.Id}> <td>{pos.Name}</td> <td> <template if:true={statusPicklist.data}> <lightning-combobox label="" value={pos.Status__c} options={statusPicklist.data.values} onchange={handleChangeStatus} > </lightning-combobox> </template></td> <td>{pos.Opening_date__c}</td> <td>{pos.Closing_date__c}</td> <td>{pos.Salary_max__c}</td> <td>{pos.Salary_min__c}</td> </tr> </template> </tbody> </table> </div> </template>

JS:
import { LightningElement, wire,track,api } from 'lwc'; import getPositions from '@salesforce/apex/positionStatusLwcController.getPositions'; import filterByStatus from '@salesforce/apex/positionStatusLwcController.getPositions' import POSITION_OBJECT from '@salesforce/schema/Position__c'; import STATUS_FIELD from '@salesforce/schema/Position__c.Status__c'; import {getPicklistValues,getObjectInfo} from "lightning/uiObjectInfoApi"; export default class PersonList extends LightningElement { positions; selectedFilter = 'All'; ///////////////////////////////////////////////// //Status filter func ///////////////////////////////////////////////// get options() { return [ { label: 'All', value: 'All' }, { label: 'Opened', value: 'Opened' }, { label: 'Closed', value: 'Closed' } ]; } handleChange( event ) { this.selectedFilter = event.detail.value; if ( this.selectedFilter === 'All' ) this.positions = this.initialPositions; else this.filter(); } @wire( getPositions ) wiredAccount( { error, data } ) { if (data) { this.positions = data; this.initialPositions = data; this.error = undefined; } else if ( error ) { console.log('Error is ' + JSON.stringify(error)); this.initialPositions = undefined; this.positions = undefined; } } filter() { if ( this.selectedFilter ) { this.positions = this.initialPositions; if ( this.positions ) { let poss = []; for ( let pos of this.positions ) { if ( pos.Status__c === this.selectedFilter ) { poss.push( pos ); } } this.positions = poss; } } else { this.positions = this.initialPositions; } } ///////////////////////////////////////////////// //Change status on field status for each position ///////////////////////////////////////////////// @wire(getObjectInfo, { objectApiName: POSITION_OBJECT }) accountMetadata; @wire(getPicklistValues, { recordTypeId: '$accountMetadata.data.defaultRecordTypeId', fieldApiName: STATUS_FIELD } ) statusPicklist; handleChangeStatus(event) { this.value = event.detail.value; } }

APEX:
public with sharing class positionStatusLwcController { @AuraEnabled( Cacheable=true ) public static List <Position__c> getPositions() { return [ SELECT Id,Name,Status__c,Opening_date__c,Closing_date__c,Salary_min__c,Salary_max__c FROM Position__c LIMIT 10 ]; } }

So, I was thinking about this:
get options() { return [ { label: 'All', value: 'All' }, { label: 'Opened', value: 'Opened' }, { label: 'Closed', value: 'Closed' } ]; }
I want to do this without label, value hardcoding. IS there a way? I guess i should make a filter method in Apex that will SELECT values for 'All' status and for other statuses.

Please, help. I am only a beginner.
chirs jordanchirs jordan
I'm Don't Understand your question you can search this question for this web (https://cancatseat.info/).
Thanks.