Page 1 of 2

Dynamic filtering of the Related Items list(Multiple values)

Posted: 23 Apr 2019
by ibarrandres
Hello,

I was following this example: https://spform.com/related-items/dynami ... point-form but I wanted to apply the filtering with multiple values instead of just one. Is this possible?

I have multiple related items in a form so I am passing the #InplviewHash value for each but I can't find a way to get it to work with multiple values filtered.

I have:

Code: Select all

window.location.hash = "InplviewHash" + $(".rfpsolicitation [webpartid]").attr("webpartid") + '=FilterField=Doc_x0020_Category-FilterValue=Direct Award';
but I would like to specify more values. like "RFP" and "RFQ"

Tried the following:

Code: Select all

window.location.hash = "InplviewHash" + $(".rfpsolicitation [webpartid]").attr("webpartid") + '=FilterField=Doc_x0020_Category-FilterValue=Direct Award&FilterField=Doc_x0020_Category-FilterValue=RFP&FilterField=Doc_x0020_Category-FilterValue=RFQ';
And:

Code: Select all

window.location.hash = "InplviewHash" + $(".rfpsolicitation [webpartid]").attr("webpartid") + '=FilterField=Doc_x0020_Category-FilterValue=Direct Award&FilterField1=Doc_x0020_Category-FilterValue1=RFP&FilterField2=Doc_x0020_Category-FilterValue2=RFQ';
The field type(Doc_x0020_Category) is a choice field (not lookup).

I looked everywhere for documentation on this and there seems to be very little. Any Ideas?

Thank you!

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 24 Apr 2019
by AlexZver
Hi!

Please consider this forum topic: viewtopic.php?f=1&t=2409&p=7649
If you have any question - feel free to ask, we are more than happy to help!

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 24 Apr 2019
by ibarrandres
Hello,

I reviewed that example but it seems it overwrites additional filters. I am looking to filter by multiple values for example only show "Direct Award", "RFP" and "RFQ". I've looked at the window.location.hash value after additional hashes get added but it always takes the last one added. The difference from what I am trying to do and the example provided above is that I need the filters applied to the same field and the example is applying to two different fields.


my window.location.hash after all filters get applied looks like this:
#InplviewHashbbac7c97-c855-42a1-b46d-25f3a8a95926=FilterField%3DDoc_x0020_Category-FilterValue%3DDirect%20Award#InplviewHashbbac7c97-c855-42a1-b46d-25f3a8a95926=FilterField=Doc_x0020_Category-FilterValue=RFP#InplviewHashbbac7c97-c855-42a1-b46d-25f3a8a95926=FilterField=Doc_x0020_Category-FilterValue=RFQ"

The blue filters don't get applied it only takes the last one that is red.

thanks for helping out!

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 25 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
Multiple hashes can only be used for multiple Related Items controls, if you want several conditions to apply to one Related Items control, you'll need to include several fields with numbers in filter like this:

Code: Select all

//first filter on page load
setHash();
 
//and attach an on-change handler that will call the filtering function wherever the value of the field changes
fd.field('Department').change(setHash);
fd.field('Department2').change(setHash);
 
//this is the actual function that filters the list
function setHash(){
  //get value
  var value =  fd.field('Department').value();
  if (!value) {
    value = "";
  }

  var value2 =  fd.field('Department2').value();
  if (!value2) {
    value2 = "";
  }
 
  value =  encodeURIComponent(escape(value)).replace(/\-/g, "%252D");
  value2 =  encodeURIComponent(escape(value2)).replace(/\-/g, "%252D");
 
  //set the URL’s hash value
  window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + "=FilterField1=Department-FilterValue1=" + value + "-FilterField2=Department2-FilterValue2=" + value2;
}

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 25 Apr 2019
by ibarrandres
Thanks for the response!

This related item view is static so it doesn't require of changing views based on selections. I already know the values I want to filter by and I would like to use those statically. I tried your method by passing a string instead of the value variables and it wouldn't filter correctly.

Example:

Code: Select all

function setHash(){
value =  encodeURIComponent(escape("Direct Award")).replace(/\-/g, "%252D");
value2 =  encodeURIComponent(escape("RFP")).replace(/\-/g, "%252D");
value3 =  encodeURIComponent(escape("RFQ")).replace(/\-/g, "%252D");

 //set the URL’s hash value
window.location.hash = "InplviewHash" + $(".rfpsolicitation [webpartid]").attr("webpartid") + '=FilterField=Doc_x0020_Category-FilterValue=' + value + '-FilterField2=Doc_x0020_Category2-FilterValue2=' + value2 + '-FilterField3=Doc_x0020_Category3-FilterValue3=' + value3;
}
//first filter on page load
setHash();

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 25 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
Please, keep close attention to the filter hash, it's a bit different! Plus, you need to declare all variables before you can assign values to them, so don't forget to use var. If you want it to work for your case, you need to modify it, like this:

Code: Select all

function setHash(){
  var value =  encodeURIComponent(escape("Direct Award")).replace(/\-/g, "%252D");
  var value2 =  encodeURIComponent(escape("RFP")).replace(/\-/g, "%252D");
  var value3 =  encodeURIComponent(escape("RFQ")).replace(/\-/g, "%252D");
 
  //set the URL’s hash value
  window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + "=FilterField1=Doc_x0020_Category-FilterValue1=" + value + "-FilterField2=Doc_x0020_Category2-FilterValue2=" + value2 + "-FilterField3=Doc_x0020_Category3-FilterValue3=" + value3;
}

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 25 Apr 2019
by ibarrandres
Yeah I forgot to add the var's on the example but I actually declared them in spforms.

I tried this example once again and looking at the URL I am left with:

#InplviewHash78fee05a-5131-48b1-9d74-5b8fe85671e7=FilterField1=Doc_x0020_Category-FilterValue1=Direct%2520Award-FilterField2=Doc_x0020_Category2-FilterValue2=RFP-FilterField3=Doc_x0020_Category3-FilterValue3=RFQ

but the filter doesn't get applied. again here is my example:

Code: Select all

function setHash(){
var value =  encodeURIComponent(escape("Direct Award")).replace(/\-/g, "%252D");
var value2 =  encodeURIComponent(escape("RFP")).replace(/\-/g, "%252D");
var value3 =  encodeURIComponent(escape("RFQ")).replace(/\-/g, "%252D");
 
  //set the URL’s hash value
window.location.hash = "InplviewHash" + $(".rfpsolicitation  [webpartid]").attr("webpartid") + "=FilterField1=Doc_x0020_Category-FilterValue1=" + value + "-FilterField2=Doc_x0020_Category2-FilterValue2=" + value2 + "-FilterField3=Doc_x0020_Category3-FilterValue3=" + value3;
}
setHash();

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 26 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
Just copied and pasted code into my designer, only changed the field names, here's the result:
RelatedItemsDynamic2.png
RelatedItemsDynamic2.png (4.29 KiB) Viewed 2050 times
Now, if it doesn't work for you, check the URL, please. Then, you can click the arrow near each column name and see how SharePoint would filter these fields differently (it works the same way):
RelatedItemsDynamic3.png
RelatedItemsDynamic3.png (14.12 KiB) Viewed 2050 times

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 26 Apr 2019
by ibarrandres
Nikita,

Thanks again for the help.

In your example above you are filtering three different fields with single values. I would like to apply the three values into one(Document Category column.
2019-04-26_7-57-40.png
2019-04-26_7-57-40.png (62.2 KiB) Viewed 2049 times
I need Doc Category to filter by Direct Award, RFP and RFQ.

Re: Dynamic filtering of the Related Items list(Multiple values)

Posted: 26 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
In this case, just use the following line:

Code: Select all

window.location.hash = "InplviewHash" + $(".rfpsolicitation  [webpartid]").attr("webpartid") + "=FilterFields1=Doc_x0020_Category-FilterValues1=Direct%2520Award%253B%2523RFP%253B%2523RFQ";