0

Here's the link to the similar question How to filter Data in dataTable lwc based on the input in search bar?

The above works fine with non-lookup fields but doesn't seem to be working in my case.

If I use regex.test(row.Name), I'm able to search the records based on Name column however, one of my columns has fieldName: Owner.Name and the search isn't working.

Error: [Cannot read properties of undefined (reading 'Name')]

.js code snippet:

updateSearch(event) {
     var regex = new RegExp(event.target.value, 'i')
     this.data = this.testSearch.filter(
        row => regex.test(row.Owner.Name) 
     );      

Any idea on above?

2
  • 2
    What do you mean "doesn't seem to be working", exactly? How are we supposed to help you if we don't know exactly what's wrong?
    – sfdcfox
    Commented Feb 24, 2022 at 17:37
  • @sfdcfox I meant the search isn't working, updated my question.
    – SFShrek
    Commented Feb 24, 2022 at 17:42

1 Answer 1

0

Instead of using Owner.Name as a fieldName in Columns do this:

Old format:

{ label: 'Owner', fieldName: 'Owner.Name'}

New format:

{ label: 'Owner', fieldName: 'Owner'}

and Update the code to include Owner.Name in your array of columns like below:

this.data = data.map((row) => ({ Owner: row.Owner.Name }));

this will make the search method as:

updateSearch(event) {
     var regex = new RegExp(event.target.value, 'i')
     this.data = this.testSearch.filter(
        row => regex.test(row.Owner) 
     );
}

This is working fine for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .