I am building a search web part in which, I am filtering the data from the SharePoint document library based on the value in the skillset column.

It is a managed metadata column.

Below is the structure of the single record.

ID: 746
OfficeLocation: {Label: "India", TermGuid: "7f1ef83c-0dbd-463d-8fda-5d1ea4506bb5", WssId: 5}
Skillset: (4) [{…}, {…}, {…}, {…}]
Title: null

The skillset is again an array of objects as below.

enter image description here

0: {Label: "ASP.Net", TermGuid: "0207fb4e-cff9-43b9-8c27-2225ff2bde78", WssId: 24}
1: {Label: "Java", TermGuid: "4b01e476-0864-434b-9dfe-d576b4451c3f", WssId: 7}
2: {Label: "Javascript", TermGuid: "1d0c4e05-c1f6-4f3a-accd-66e5f334d3f0", WssId: 32}
3: {Label: "SQL Server", TermGuid: "4626fe15-bc26-462a-bc6c-9d1701ba14ed", WssId: 30}

Here, I want to filter these records based on the skillset value.

So, if I enter "java" as my search keyword then only those records should come which has the skillset label value as "java".

Currently, I used the .some function which returns the records who has the skillset javascript because it contains the word java in it.

 (f) =>
  f.Skillset.length > 0 &&
  f.Skillset.some((s) => s.Label == element.name)

Can anyone help here to filter the data with the exact skillset?

  • 1
    Hi,try this one: pdfItems.filter( (f) => f.Skills.length > 0 && f.Skills.filter(s=>s.Label== "Java").length>0)); – Dikesh Gandhi Nov 11 '20 at 13:01

Please try the below code in browser console:

var pdfItems = [{ID:1,
Skills: [{Label: "ASP.Net", TermGuid: "0207fb4e-cff9-43b9-8c27-2225ff2bde78", WssId: 24},
{Label: "Java", TermGuid: "4b01e476-0864-434b-9dfe-d576b4451c3f", WssId: 7},
{Label: "Javascript", TermGuid: "1d0c4e05-c1f6-4f3a-accd-66e5f334d3f0", WssId: 32},
{Label: "SQL Server", TermGuid: "4626fe15-bc26-462a-bc6c-9d1701ba14ed", WssId: 30}]},
{ID: 2,Skills: [{Label: "ASP.Net", TermGuid: "0207fb4e-cff9-43b9-8c27-2225ff2bde78", WssId: 24}]}];

 console.log(pdfItems.filter( (f) => f.Skills.length > 0 && f.Skills.filter(s=>s.Label== "Java").length>0)));

It will return only one object in which skills have 'Java'.

I think this question rightfully belongs to stake overflow site. :)

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