3
votes

I have a listview on a page that displays several records. Every record has "ID" column (1,2,3,4 ... ). I'd like to let user filter listview with text field. User types "ID" value he/she searches, clicks "find" button and listview should display the record that meets user criteria. I added form webpart with text field and connected it to list via connections property as described here:

How do you filter a SharePoint list with a text field?

That works great for the very first time: when user types value and presses "search" - listview is filtered as expetected.

The problem happens when user tries to remove filter. 1. User can't remove filter through drop down menu for "ID" column. It simply doesn't work though column is displayed as filtered (special icon is displayed). 2. User can't remove filter by removing all symbols in text field and clicking "search" once again.

What I do wrong?

I have found similar problem: http://www.dotnetspark.com/links/47412-unable-to-clear-filter-on-sharepoint-list.aspx

but no solution was proposed :(

UPDATE

This is temporary solution for text field - when it's empty and user clicks "search" the whole page is simply refreshed. I'm not sure if it is best practice (I'd prefer to update listview without page refreshing).

<div onkeydown="T1keydown()">
  <input type="text" name="T1" id="T1T1"/>
  <input type="button" value="Search" onclick="T1apply()"/>

  <script type="text/javascript">

function T1keydown() {
  if (event.keyCode == 13) 
    T1apply();
}

function T1apply() {
  var text = document.getElementById("T1T1").value;
  if (text.length > 0) 
  {
    _SFSUBMIT_;
    return;
  }
  window.location.href=window.location.href;
}

  </script>
</div>
1

1 Answers

0
votes

probably you can like this. Just add a Content Editor/Html form webpart. And add below code.This way you get more control over look and feel and what you want to do.

$(document).ready(function() {


  $("#search").click(function() {
    var id = $("#IDVal").val();
    var params = "FilterFeild1=ID&FilterValue1=" + id;
    //alert(params);
    location.href = location.href.split("?")[0] + "?" + params;


  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<input type="text" id="IDVal" />
<input type="button" id="search" value="Search" />