Problem
While going back to basics, that is on-prem SharePoint, I needed to create list view search box to another page. Meaning that the other page (not the the list view page) needed to have search box and button. Typing in query and pressing the button would redirect to the list view and do the search like user would've typed in the search in the list view search box.
I was certain there was some querystring parameter one could define for this to work, but couldn't find, so after some trial and error I found the correct one!
Solution
In your link that points to list view, use querystring parameters View and InplaceSearchQuery. View contains the GUID of the view you want to show, and InplaceSearchQuery contains the query that is executed towards that view.
So a simplest example of this is to add this to Script Editor Web Part:
<input type="text" id="inputBox" placeholder="Enter search query..." style="width:300px">
<button onclick="redirectToURL()" type="button">Search</button>
<script>
function redirectToURL() {
var inputValue = document.getElementById('inputBox').value;
var baseURL = 'http://intranet.company.com/Lists/RequestForOffer/AllItems.aspx?view={DD04F0F8-6441-4DD9-9515-29EE952C9306}&InplaceSearchQuery=';
var fullURL = baseURL + encodeURIComponent(inputValue);
window.location.href = fullURL;
}
</script>
Only downside here is that the list view search box doesn't show the query text, but that you could do by some JavaScript magic injected to the list view page.
No comments:
Post a Comment