Typescript array object Filter - dynamic filter conditions, Search Refiners Sharepoint

Dhanasekaran G 1 Reputation point
2021-01-25T04:01:09.863+00:00

Please I need a help on below scenario in Typescript, SharePoint Search.

I have Collection of Array something like this,

let _SelectedBusinessUnits =[
{ "fileName": "XYX.doc", "Region": "APAC", "Country":"Australia;China", "LOB": "Auto;Business Auto", SubLOB" : "Standard Auto" },
{ "fileName": "XYX2.doc", "Region": "UKIG", "Country":"UK;Germany", "LOB": "Wordings;Business Wordings", SubLOB" : "Super Wordings;YYY" },
{ "fileName": "XYX3.doc", "Region": "LTAM", "Country":"Japan", "LOB": "Endorsments;Business Endorsments", SubLOB" : "Super Endorsement" },
{ "fileName": "XYX4.doc", "Region": "APAC", "Country":"Australia:China", "LOB": "Auto;Business Auto", SubLOB" : "Standard Auto;XYHC" },
{ "fileName": "XY.doc", "Region": "UKIG", "Country":"UK, Germany", "LOB": "Wordings;Business Wordings", SubLOB" : "Super Wordings" },
{ "fileName": "XYX.pdf", "Region": "LTAM", "Country":"Japan", "LOB": "Endorsments;Business Endorsments", SubLOB" : "Super Endorsement" },
{ "fileName": "XYX.docx", "Region": "APAC", "Country":"Australia;China", "LOB": "Auto;Business Auto", SubLOB" : "Standard Auto" },
{ "fileName": "XYX.html", "Region": "UKIG", "Country":"UK;Germany", "LOB": "Wordings;Business Wordings", SubLOB" : "Super Wordings" },
{ "fileName": "X.pdf", "Region": "LTAM", "Country":"Japan", "LOB": "Endorsments;Business Endorsments", SubLOB" : "Super Endorsement" },]

I have filter conditions in another array of objects.

let filercondition =[{
{"Region": "UKIG"},
{"Region": "APAC"}
{"LOB":'Wordings},
{"Country":'UK'}

 }]

Now, i have scenario to filter the items based on the value I have in filter condition . [i.e I will select Region, Sublob or Lob etc..I have respective multiselect dropdowns like Regions, country and lob and sublobs]

Based on the selection I do in the multiselect dropdowns i need to fetch. It is like refiner filters in search. Please assist ASAP. Thanks a lot !!

Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-01-25T06:18:12.627+00:00

    Hi @Dhanasekaran G ,
    You could try to use Array filter() function.This function will return a new array with all elements that pass the test implemented by the provided function.
    Test code for your reference:60030-code.txt
    60072-carbon.png
    Test result:
    59990-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.