0

I am looking to filter list data by appending to the URL of the list with the query text. This is the only solution I've found to my problem, filtering data using wildcards.

For example, If I'm viewing my All Items list view, I can search Project IDs by adding FilterName=Project_x0020_ID&FilterMultiValue=10* this works directly on the list page that I am viewing and returns all items with a Project ID that begins with 10.

Now, I don't want to have my users changing the URL directly. They want to be able to type the FilterMultiValue= value into a textbox and have that automatically added to the URL.

In SharePoint 2013 I have added a Script Editor to my List view page. However, I cannot get this section to append to the URL. Here is the code that I am using to make this happen, currently when the button is clicked, nothing happens.

<P>&nbsp;</P>
    <P>Enter your search query: <INPUT id=textboxSearchQuery size=75> <INPUT onclick=RedirectSearchQuery(); value=Search type=button> </P>
    <P><EM>Use * as wildcard</EM></P>
    <SCRIPT language=javascript type=text/javascript src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js">
</SCRIPT>

    <SCRIPT language=javascript type=text/javascript>
    function RedirectSearchQuery(){
    var url=$(location).attr(‘href’).split("?")[0] + "?";
    var sQuery=$("#textboxSearchQuery").val();
    if(sQuery!=""){
    url=url + "FilterName=Project_x0020_ID&FilterMultiValue=" + sQuery
    $(location).attr('href',url);
    }
    }
    </SCRIPT> 

If anyone has had success doing something similar to this please let me know a fix that you were able to implement.

  • You're missing a semi-colon after url = url + "..." + sQuery. Does your console show any other errors? – Erin L Jun 20 '16 at 17:28
  • JS has automatic semicolon insertion (ASI) so this should not be the problem. What I notice is that your code has illegal characters around href in the line var url=$(location).attr(‘href’).split("?")[0] + "?"; – Daniel Stölzner Jun 20 '16 at 17:32
  • I just tried with my console open and got the error: Reference Error: RedirectSearchQuery is not defined onclick() – AddieCaddy Jun 20 '16 at 17:33
0

I tested your code and removing the illegal characters around href in line 2 solves the problem:

function RedirectSearchQuery() {
    var url = $(location).attr('href').split('?') [0] + '?';
    var sQuery = $('#textboxSearchQuery').val();
    if (sQuery != '') {
        url = url + 'FilterName=Project_x0020_ID&FilterMultiValue=' + sQuery
        $(location).attr('href', url);
    }
}
  • Was just coming back to say that this worked. – AddieCaddy Jun 20 '16 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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