The fast List search in SharePoint 2010
Have you ever noticed the search in SharePoint 2013 lists? It is pretty cool, because you get what you want and that on a fast way. Did you or a client ever had the wish to use it on a SharePoint 2010 to? Well that is pretty easy. All you need to do is to add a Code Editor Web Part over your list. Enter into the list the following code:
What this code is doing is to add a textbox into the UI. This box calles the function quickSearch with every change of its value. The function checks if the values lenght is not lower than the value of minimalCharacters. If it is not this functions loops all list elements and checks for the content. If the content contains the searchterm this element won't be touched (or will be set visible if it is not), but if i doesn't contain the term this element will be hidden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <script type="text/javascript"> var minimalCharacters = 3; function getElementsByCssClass(sTagName, sClassName) { var results = new Array(); var allTagElements = document.getElementsByTagName(sTagName); for (i = 0; i < allTagElements.length; i++) { if(allTagElements[i].className == sClassName) results.push(allTagElements[i]); } return results; } function getTxt(obj) { if(obj.innerText) return obj.innerText; else return obj.textContent; } var lvRows = null; function quickSearch(term) { if (term.length >= minimalCharacters){ if(lvRows == null) { var lvTable = getElementsByCssClass("table","ms-listviewtable")[0]; lvRows = lvTable.childNodes[0].childNodes; } for(i = 1; i < lvRows.length; i++) { if(getTxt(lvRows[i]).toLowerCase().indexOf(term.toLowerCase()) > -1) { lvRows[i].style.display = "table-row"; } else lvRows[i].style.display = 'none'; } } } </script> Live Search on View: <input name="t_in" id="txtINPUT" onkeyup="quickSearch(this.value)" type="text"/> |
What this code is doing is to add a textbox into the UI. This box calles the function quickSearch with every change of its value. The function checks if the values lenght is not lower than the value of minimalCharacters. If it is not this functions loops all list elements and checks for the content. If the content contains the searchterm this element won't be touched (or will be set visible if it is not), but if i doesn't contain the term this element will be hidden.
Comments
Post a Comment