Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list of products with hundreds of entries. Each product has contact details with it as well as company information etc. I would like to be able to run a search on this list and return matches from any column.

For example, currently using a text query filter I am able to return results that match the exact term typed in from one particular column, but ideally I'd like it to return any record in which the query matches any column.

Is this possible?

share|improve this question
1  
Why not use site search? I you use the search box on the page of the list it searches the list. –  Remko Apr 25 '13 at 13:24
    
I have considered this option, but the ideal scenario is filtering the list. –  Charles Baker Apr 29 '13 at 8:30
add comment

1 Answer 1

So, what we are going to do is add a short jQuery script on our page. This script will read the text in a text box and then filter all the rows in a list view and only show those rows that contain text that’s in the text box. To be more exact the script will:

1.Find the specific table we want to filter (don’t filter on EVERY row on the page, that would hurt performance).

2.Iterate through each row in that table.

3.Strip off the html tags (we don’t want those affecting our search results, and the speed of the string search)

4.Search the remaining text to see if the text in the filter box exists in what’s left

5.Hide/Show rows accordingly

http://geekswithblogs.net/SoYouKnow/archive/2011/01/26/sharepoint-list-views-ndashquick-amp-easy-jquery-filter.aspx

<SCRIPT type="text/javascript"src="/Scripts/jquery.min.js"></SCRIPT>

<SCRIPT type=text/javascript>

jQuery(document).ready(function($){
    //attach a function to the keyup event on the filter box
    $('#filterInput').keyup(function() 
    {
        DynamicFilter($('#filterInput').val());
    });
})

//strip off html taqs
function stripHTML (field) {
    return field.replace(/<([^>]+)>/g,'');
}

function DynamicFilter(text)
{
    //find out list view (default class for a listview is "ms-listviewtable"
    $('table [class="ms-listviewtable"]').find('tr').each(function()
        {
            //don't filter out the header row
            if ($(this).attr("class") != "ms-viewheadertr ms-vhltr")
            {
                //get the html for the row and strip off the html tabs
                source = stripHTML($(this).html());

                //check to see if the filter text exists in the remaining text
                if (source.indexOf(text) < 0)
                {
                    //hide the row if it doesn't contain the text
                    $(this).hide();
                } else {
                    //otherwise show it
                    $(this).show();
                }
            }
        }
    );
}

</script>

<div id="mainDiv">
    <table>
        <tr>
            <td class='Filter' width='125px'>Search: <input type="Text" id="filterInput" ></td>
        </tr>
    </table>
</div>

you can use other methods like binding to the list and from the dataset ;) can be done quite easily but requires a bit of coding :)

http://howinaspnet.blogspot.co.uk/2010/07/how-to-filter-data-in-dataset-dataview.html

share|improve this answer
    
Thanks for this. I will give it a go later today. –  Charles Baker Apr 29 '13 at 8:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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