3

I have a content search webpart that needs to show a list of events. It will page through month by month. The default month on the homepage will be the current month. Each time the user changes the month I would like to do a search on the month currently displayed.

I found Query variables in SharePoint Server which shows all the tokens that I can access in my search query builder and I first tried putting the date into some parameters in the QueryString of the url.

RefinableDate00>={QueryString.MyStartDate} AND RefinableDate00<=QueryString.MyEndDate}

Where I change the url window.location.search string to include parameters that give values to start and end the currently displayed month. But each time I change the URL the page reloads and I would prefer not to do that.

I tried putting MyStardDate into the URL hash (since that won't reload the page), but I can't find a way for my query builder to read that.

Looking down the list of tokens on that page I can't see anything to just read a value from the page.

Any suggestions?

1

1 Answer 1

1

Based on month changes, you should be passing a complete query including query strings (possibly refiners) so page load shouldn't affect the search results.

 var startdate= JSRequest.QueryString["MyStartDate"];
 var enddate= JSRequest.QueryString["MyEndDate"];
 var filtersArray = [];
 filtersArray.push("MyStartDate=" + startdate);
 filtersArray.push("MyEndDate=" + enddate);
 var filter = _spPageContextInfo.serverRequestPath + "&" + filtersArray.join("&");
 window.location = filter;

You may build similar query with refiners only, and filter results without having to do a page refresh. Remember, refiners will append the hash so no page refresh, but query string performs page refresh.

var filtersArray = [];
var refinersArray = [];
.
.
//build arrays of query string and refiners
.
.
var refiners = '#Default={"k":"*","r":[' + refinersArray.join(",") + ']}';
var filter = _spPageContextInfo.serverRequestPath + "?" + filtersArray.join("&") + refiners + '&';
window.location = filter;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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