0

i have downloaded a very nice script for realtime filter for sharepoint list: https://instantlistfilter.codeplex.com/

i'm adding the code below. and i have two issues with it. 1. it is calling Google service, and i wonder if i can avoid that, since i'm not sure my company will be happy to know this list is going to Google each time someone is filtering it. 2. i'm getting error "Object doesn't support this property or method" for line 106 of the code, which causing the ribbon of the site including the "site action" dropdown button to disappear. I know it is related to the "show" command, but i have no clue how can i fix it.

As said above, i'm using sharepoint 2010. To install this code, i created a text document with it in my documents folder, then created below my list a CEW which is linked to that document. this method worked for me in another page with no issues.

Here is the full code as downloaded from the site above:

<script src="http://www.google.com/jsapi"></script>
<script>
 google.load("jquery", "1.2.6");
 google.setOnLoadCallback(function() { 
 $(document).ready(function()
 {  
   jQuery.extend(jQuery.expr[':'], {
   containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0}
});


$("table.ms-listviewtable tr.ms-viewheadertr").each(function()
{
    if($("td.ms-vh-group", this).size() > 0)
    {
        return; 
    }

    var tdset = "";

    var colIndex = 0;

    $(this).children("th,td").each(function()
    {
        if($(this).hasClass("ms-vh-icon"))
        {
            // attachment
            tdset += "<td></td>";
        }
        else
        {
            // filterable
            tdset += "<td><input type='text' class='vossers-filterfield' filtercolindex='" + colIndex + "' /></td>";                
        }

        colIndex++;
    });

    var tr = "<tr class='vossers-filterrow'>" + tdset + "</tr>";

    $(tr).insertAfter(this);
}); 


$("input.vossers-filterfield")
    .css("border", "1px solid #7f9db9")
    .css("width", "100%")
    .css("margin", "2px")
    .css("padding", "2px")
    .keyup(function()
    {           
        var inputClosure = this;

        if(window.VossersFilterTimeoutHandle)
        {
            clearTimeout(window.VossersFilterTimeoutHandle);
        }

        window.VossersFilterTimeoutHandle = setTimeout(function()
        {
            var filterValues = new Array();

            $("input.vossers-filterfield", $(inputClosure).parents("tr:first")).each(function()
            {               
                if($(this).val() != "")             
                {
                    filterValues[$(this).attr("filtercolindex")] = $(this).val();
                }
            });     


            $(inputClosure).parents("tr.vossers-filterrow").nextAll("tr").each(function()
            {
                var mismatch = false;

                $(this).children("td").each(function(colIndex)
                {
                    if(mismatch) return;

                    if(filterValues[colIndex])
                    {
                        var val = filterValues[colIndex];

                        // replace double quote character with 2 instances of itself
                        val = val.replace(/"/g, String.fromCharCode(34) + String.fromCharCode(34));                         

                        if($(this).is(":not(:containsIgnoreCase('" + val + "'))"))
                        {
                            mismatch = true;
                        }                       
                    }
                });

                if(mismatch)
                {
                    $(this).hide();
                }
                else
                {
                    $(this).show();
                }       
            });             

        }, 250);
    });
   });
 });
</script>

1 Answer 1

0

From what I can see, you're only using the Google code to download jQuery and setup callback when the script gets loaded. To avoid downloading from Google, can't you just load a local copy jQuery?

Download a minimized version of jQuery and upload it to your SharePoint site (Site Assets library or elsewhere).

Then in your code above replace this line

<script src="http://www.google.com/jsapi"></script>

with

<script src="/SiteAssets/{your jquery file name}"></script>

then you can just replace

google.setOnLoadCallback(function() { 
    $(document).ready(function() {  
        jQuery.extend(jQuery.expr[':'], {
            containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0
        }
    });
});

with

$(function(){
    jQuery.extend(jQuery.expr[':'], {
        containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0
    }
});
2
  • Ok. finally - this change of using it this way - solve the other problem as well!! Dec 11, 2013 at 11:59
  • @user3016795 you'd have to give more info. Line 106 doesn't exist for me and I can't run this code in jsFiddle. Open up developer tools and add start stepping through the code Dec 12, 2013 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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