Вопрос

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.

Это было полезно?

Решение

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);
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top