Friday, June 2, 2017

Add List Filter Search - SharePoint 2013

How to add custom filter search in SharePoint list?



Add Content editor web part













Instert code:

<script type="text/javascript">
 function RedirectUrl() {
 var tb = document.getElementById("tbSearch").value;
 var cs = document.getElementById("sfield").value;
 var url = "";

 if (tb != "") {
  if (cs == "Title" || cs == "Country"){
  url = "FilterField1=" + cs + "&FilterValue1=" + tb;
  window.location.href = "AllItems.aspx?" + url;
  }
  else { 
  url = "FilterName=" + cs + "&FilterMultiValue=*" + tb + "*";
  window.location.href = "AllItems.aspx?" + url;
  }
  }
  else {
  return false;
  }
 }
 function ClearUrl() {
 window.location.href = "AllItems.aspx";
 }
</script>
Search Field: <select id="sfield">
<option selected value="Title">Title</option>
<option value="Country">Country</option>
</select>
&nbsp;
Search text: <input type="text" id="tbSearch" />
<input type="button" id="btnSearch" value="Search" onclick="return RedirectUrl();" />
<input type="button" id="btnClear" value="Clear" onclick="return ClearUrl();" />















Save page.














Insert value in search box

1 comment:

  1. Hello the script works for me only if the column Country content has only a word without spaces, what happen if I try to search "United States" it didn't find it

    ReplyDelete