Sibirman's preferred answer will only return the original request for submission. Custom filters are actually added to the URL (as part of the InplviewHash line) when the user applies the filter action.
eg. # InplviewHashf16272c0-c177-42d7-9638-35fd75c90348 = WebPartID% 3D% 7BF16272C0 - C177--42D7--9638-35FD75C90348% 7D- FilterField1 % 3DProjectRef- FilterValue1 % 3DProject% 25201- Filter Filter % 2 % 3D-Filter
There are functions inside INPLVIEW.js and other SP JavaScript files in / _layouts that include functions to decode this and reinitialize the view, but I have not been able to decrypt it all.
DecodeHashAsQueryString and InitGridFromView are a good place to start.
I ended up writing my own code to check the hash string, and then cross off the key / value pairs.
var uri = window.location.href; var hashIndex = uri.search("#"); var filter = false; if (hashIndex == -1) { // Wasn't found alert('No filters applied!'); // ...go with default query. } else { // # found. Get hashstring var hashStr = uri.substring(hashIndex); newStr = DecodeHashAsQueryString(hashStr); var trStr = newStr.substring(newStr.indexOf("FilterField")); var retStr = trStr.replace(/%3D|&/g,",").replace(/%2520/g," "); retStr = retStr.replace(/FilterField[0-9]+,|FilterValue[0-9]+,/g,"") var filtArray = retStr.split(','); // "MyField1","MyValue1",...
And applying them to my own query, which does not contain restrictions, therefore, all elements that match the filter criteria are returned.
If you want to handle fields other than opr text selection, you need to take one more step and get the field type so that you can change the type of query value for each field as needed.
source share