Sharepoint 2013 provides a couple of alternatives to filter lists or libraries out of the box.

  1. Metadata Navigation and Filtering
  2. Filtering by passing parameters in the URL

Metadata Navigation and Filtering

This is one of the most common types of filtering and has been blogged about a lot.  To enable this kind of filtering you need to go to

Site Settings > Manage Site Features > activate Metadata Navigation and Filtering.

Activate Metadata Feature

Once activated go to the list/library setting and select “Metadata Navigation Settings”

Select the column that you want to filter on.

Select Filter Column

On completing the process you would be able to filter your document library like the image shown below

 Metadata Navigation

Filtering by passing a parameter in the URL

The scenario: I have a document library and I need to filter the documents based on a date range. For instance I need to filter all documents created between 1st Jan 2014 to 31st March 2014.

Now the previous method of metadata navigation is no longer feasible.

To enable us to filter on a range we need to do 2 things

Add a calculated column:

We need to add a calculated column, in this example CustomCreatedDate, which will be based on our Created column. This column is nothing but an exact replica of our created column.

This is needed as we cannot filter twice on the same column.

Add the script in a CEWP (Content Editor Web Part):

/*Include jQuery so we can get a datepicker*/
<link rel="stylesheet" href="jquery-ui.css"/>
<script src="jquery-1.9.1.js"></script>
<script src="jquery-ui.js"></script>

<script>
//jQuuery datepicker
$(function() {
    $( "#startdatepicker" ).datepicker();
    $( "#enddatepicker" ).datepicker();
});
</script>

<script type="text/javascript">
/*Entry point to our script*/
function getFilter()
{
    var sourceURL =document.URL; //get the URL
	/*
    Remove existing querystrings added by our script and gives us a clean URL.
    This removes the parameters FilterField1,FilterOp1,FilterValue1,FilterField2,FilterOp2,FilterValue2
    */
    var url = removeParam(sourceURL);
    var from = document.getElementById('startdatepicker').value;
    var end= document.getElementById('enddatepicker').value;
    if(from!='' && from !='undefined')
    {
        if(end!='' && end!='undefined')
        {
            if(from <= end)
            {
            var startDate = new Date(from)
            var toDate = new Date(end);
            var startdate=startDate.format("yyyy/MM/dd");//convert format yyyy/MM/dd. Here we are using the format prototype.
            var enddate=toDate.format("yyyy/MM/dd");
            window.location = url+'FilterField1=Created&FilterValue1='+startdate+'&FilterOp1=Geq&FilterField2=CustomCreatedDate&FilterValue2='+enddate+'&FilterOp2=Leq';
            }
            else
            {
            alert("Please ensure that the To Date is greater than or equal to the From Date.");
            return false;
            }
        }
        else
        {
            alert("Please select To date");
            return false;
        }
    }
    else
    {
        alert("Please select From date");
        return false;
    }
}

function removeParam(sourceURL) {
    var rtn = sourceURL.split("?")[0],
        param,
        params_arr = [],
        queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
    if (queryString !== "") {
        params_arr = queryString.split("&");
        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
            param = params_arr[i].split("=")[0];
            if (param === "FilterField1") {
                params_arr.splice(i, 1);
            }
            if (param === "FilterValue1") {
                params_arr.splice(i, 1);
            }
            if (param === "FilterOp1") {
                params_arr.splice(i, 1);
            }
            if (param === "FilterField2") {
                params_arr.splice(i, 1);
            }
            if (param === "FilterValue2") {
                params_arr.splice(i, 1);
            }
            if (param === "FilterOp2") {
                params_arr.splice(i, 1);
            }
        }
        rtn = rtn + "?" + params_arr.join("&");
    }
    else
    {
        rtn=rtn+"?";
    }
    return rtn;
}
</script>

From: <input type="text" id="startdatepicker"/> To: <input type="text" id="enddatepicker"/><input id="btnFilter" onclick="getFilter()" type="button" value="Filter" />
</p>