Monday, November 26, 2012

SPJS Charts - Dynamically Select Filter Item

I've been using SPJS charts to make google charts with data from sharepoint lists. If you use a custom drop-down filter, you may want to dynamically select items in the drop-down like I did.

An example: You're using a drop-filter which filters the results by week, but you always want it to select last week.

Snippet:


function manualLoad(){
loadManually = false;
spjs_GenerateChart();

Date.prototype.getWeek = function() {
     var onejan = new Date(this.getFullYear(),0,1);
     var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
 var dayOfYear = ((today - onejan + 1)/86400000);
 return Math.ceil(dayOfYear/7)
};

$("#MyChart1_CustomFilterSelect_Week").val(new Date().getWeek()-1).change();
}

No comments:

Post a Comment