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
AD1418AD1418 

datatable search not working in lwc

Hi Folks,

I am facing issue in lwc datatable search. The search results are not getting displayed. below is the code:-

Apex Controller:
public with sharing class issueLogController {
    
     @AuraEnabled(cacheable=true)
    public static list<Issue_Log__c> searchLoggedIssues(String searchKey, String sortBy, String sortDirection){
        
        string query = 'select Id, Name, Issue_Description__c, Issue_Priority__c, Resolved__c from Issue_Log__c';
        if(searchKey != null && searchKey != ''){
            string key = '%' + searchKey + '%';
            query += 'where Name LIKE :key';

        }
        if(sortBy != null && sortDirection != null){
            query += 'ORDER BY ' + sortBy + ' ' + sortDirection;
        }
        return Database.query(query);
    }
}

html :-
 
<template>
    <lightning-card title="Logged Issues Search" >
        <div class="slds-m-around_medium">
            <lightning-input type="search" onchange={handleKeyChange} class="slds-m-bottom_small" label="search"
                                value={searchKeyword}>
            <lightning-datatable key-field="id" data={data} columns={cols} sorted-by={sortedBy} 
                                sorted-direction={sortedDirection} onsort={sortColumns} >

            </lightning-datatable>

            </lightning-input>
        </div>
    </lightning-card>
    
</template>

js file :-
 
import { LightningElement, api, track, wire } from 'lwc';
import searchLoggedIssues from '@salesforce/apex/issueLogController.searchLoggedIssues';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import {refreshApex} from '@salesforce/apex';

const columns = [
    {label: 'Issue Log Name', fieldName: 'Name', sortable: true},
    {label: 'Issue Description', fieldName: 'Issue_Description__c', sortable: true},
    {label: 'Issue Priority', fieldName: 'Issue_Priority__c', sortable: true},
    {label: 'Issue Type', fieldName: 'Issue_Type__c', sortable: true},
    {label: 'Issue Resolved ?', fieldName: 'Resolved__c', type: 'boolean'}
    
    ];

export default class IssueListSearchChildLwC extends LightningElement {

    @track cols = columns;
    @track error;
    @track data;

    @api sortedBy = 'Name';
    @api sortedDirection = 'asc';
    @api searchKeyword = '';

    @track result;

    @wire(searchLoggedIssues, {
        searchKey: '$searchKeyword',
        sortBy: '$sortedBy',
        sortDirection: '$sortedDirection'
    })
    getIssues(result){
        this.result = result;
        if(result.data){
            this.data = result.data;
        } else if(result.error){
            this.error = result.error;
        }
        console.log('test******');
    }

    sortColumns(event){
        this.sortedBy = event.detail.fieldName;
        this.sortedDirection = event.detail.sortDirection;
        return refreshApex(this.result);
    }

    handleKeyChange(event){
          this.searchKeyword = event.target.value;
          return refreshApex(this.result);
      }
}
Need some assistance on this. Any help will be much appreciated.

Thanks
​​​​​​​