0

I'm trying to filter a list, something like the OOTB WP, but more flexible. The problem with the webpart is that the user has to input the exact contents of the item he wants to find. I would like the webpart to operate more like a regular search bar. The problem is that at the company I work at I have the search scopes disabled, as well as the share point designer.

Is there a way to do this, maybe with some coding?

4

Note:

in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column

That means given answers may not apply for newer SharePoint versions

For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back


Original answer:

Trick is to attach a JavaScript keyup event to the existing Searchbox for every ListItem (in this case above the Searchbox in the DOM, because events bubble up anyway)

Each script can check against any content you can reference in a Calculated Column... that means no enumerables like Person fields or Multiple Select Choices.

If you stuff it all in a Calculated Column (set to datatype=Number)

All it takes is:

=" <img src=""_layouts/images/blank.gif"" onload=""{"
 & "var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"
 & "TR.parentNode.parentNode.parentNode.addEventListener('keyup',"
 & "(function(keyevent){"
    & "this.style.backgroundColor='" 
    & [Task Name] 
    & "'.indexOf(keyevent.srcElement.value)===-1?'lightcoral':'lightgreen'}).bind(TR))"
 & "}"">"

The whole clue (and JavaScript magic) is the IMG is loaded inside the TR, thus bind(TR) gives you the correct this scope to set the backgroundColor.

Step by step building instructions at: http://www.viewmaster365.com/#/Create/SearchFilter

You could also do it with SP2013 Client Side Rendering code... but that requires some 20 lines more JavaScript boilerplate code.... AND a separate scriptfile... AND a JSlink on every View you want to use it.

iCC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.