0

I am complete novice to JS and LWC. I am trying to pass multiple params to ma APEX class. And still getting "[wrapper is not defined]" In the example, i am passing just one string. The goal is to eventualy have searchable LWC datatable with multiple params. I can do it with one param. The issue is with multiple once - hence trying to learn wrapper approach. Thank you for the input.

js:

export default class PTHDatatable extends NavigationMixin(LightningElement) {
    
    PTSearchValue;
    dateFrom;
    displayResults;
    columns = columns;
    handlePTSearch(event){
        this.PTSearchValue=event.target.value;
        this.handleSearch();
    }
 
    handleSearch(){
        let parameterObject = {
            PTSearch: this.PTSearchValue,
        };
        getData({wrapper: parameterObject})
            .then((result)=>{
            this.displayResults=result;})
        
    }

Wrapper class

 public with sharing class CustomWrapper {
            
            @AuraEnabled
            public String PTsearch { get; set; }
    }

And html

<template>
    <lightning-card title="Project task search">
        <lightning-button onclick={handleclick} value="Create AR" label="Create AR"></lightning-button>
        <lightning-input type="text" placeholder="Enter search value" onchange={handlePTSearch} class="slds-m-arpund_medium"></lightning-input>
        <lightning-input type="date" value="4.11.2022" placeholder="Enter search value" onchange={handledateFrom} class="slds-m-arpund_medium"></lightning-input>
        <lightning-datatable
                key-field="id"
                data={displayResults}
                columns={columns}
                onrowaction={handleRowAction}>
        </lightning-datatable>
    </lightning-card>
    
</template>

And APEX class

    public PTHDatatable() {
    }

    @AuraEnabled(cacheable=true)
    public static List<Project_Task_Hours__c> getData(CustomWrapper wrapper){
        
        try {
            String PTName = '%' + wrapper.PTsearch + '%';
        List<Project_Task_Hours__c> data = new List<Project_Task_Hours__c>([SELECT Id,Name,Project_Task__c,Date__c,Project_Task_t__c 
                                                                            FROM Project_Task_Hours__c 
                                                                            WHERE Project_Task__r.Name 
                                                                            LIKE :PTName
                                                                            LIMIT 50]);
            return data;
            
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    
}

1 Answer 1

1

the problem is typo,see the difference between PTSearch and PTsearch, you are passing wrapper as:-

let parameterObject = {
            PTSearch: this.PTSearchValue,
        };

where as your method expect it as:-

let parameterObject = {
            PTsearch: this.PTSearchValue,
        };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.