none
Clear SharePoint Choice Filter WebPart

    Question

  • Hi everyone

    I have got a page setup with a list view webpart of a list called Orders.  There are then two different filter webparts that users use to filter the list view - a text filter and a choice filter.  I want to set them up so if a user clicks onto the text filter the choice filter is cleared if not already.

    I've been trying JavaScript as shown below but even though this clears the value in the choice box it doesn't actually change the choice so as soon as the page refreshes the choice value is still set:

    ChoiceBoxID.value = "";

    I've also tried ChoiceBoxID.selectedIndex = -1; but this doesn't work either.

    I'd be grateful if anyone could let me know if there's a way of getting a choice filter webpart to clear when an action occurs?  At the moment our users are having to manually change the choice back to (Empty) before entering a text search and I would much prefer if the choice could clear automatically when they select the text filter webpart.

    Thursday, March 2, 2017 12:28 PM

Answers

  • Hi,

    When working with a Choice Filter, if you select a value, then the whole page will get refreshed, and the list view web part receives the filter value and gets filtered.

    A fact you might want to know is that, the value which is set in the Choice Filter can’t simply be removed from the page source code using JavaScript, because the selected value has already been passed and saved in the list view web part.

    A possible workaround is, re-request the current page using JavaScript, then the selected value will not be stored in either the filter web part, or the list view web part.

    Here is a code demo about re-request page, you can put in into a Script Editor web part in the same page:

    <input type="button" id="ClearBtn" value="clear choice filter"></input>
    <script>
    window.onload=function(){
    	document.querySelector("#ClearBtn").onclick = function(){
    		window.location.href = "";
    	};
    };
    </script>

    Then when you click it, it will refresh the whole page and you can start working with the Text Filter web part with an unfiltered list view like this:

    Best regards,

    Patrick

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by gjayne Monday, March 6, 2017 10:41 AM
    Friday, March 3, 2017 5:03 AM
    Moderator

All replies

  • Hi,

    When working with a Choice Filter, if you select a value, then the whole page will get refreshed, and the list view web part receives the filter value and gets filtered.

    A fact you might want to know is that, the value which is set in the Choice Filter can’t simply be removed from the page source code using JavaScript, because the selected value has already been passed and saved in the list view web part.

    A possible workaround is, re-request the current page using JavaScript, then the selected value will not be stored in either the filter web part, or the list view web part.

    Here is a code demo about re-request page, you can put in into a Script Editor web part in the same page:

    <input type="button" id="ClearBtn" value="clear choice filter"></input>
    <script>
    window.onload=function(){
    	document.querySelector("#ClearBtn").onclick = function(){
    		window.location.href = "";
    	};
    };
    </script>

    Then when you click it, it will refresh the whole page and you can start working with the Text Filter web part with an unfiltered list view like this:

    Best regards,

    Patrick

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by gjayne Monday, March 6, 2017 10:41 AM
    Friday, March 3, 2017 5:03 AM
    Moderator
  • Hi,

    Just want to know if my suggestion helpful to you?

    Best regards,

    Patrick


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, March 6, 2017 10:21 AM
    Moderator
  • Hi Patrick

    Yes that was exactly what I needed, thank you for your help.

    Monday, March 6, 2017 10:41 AM