SharePoint 2010 – Autozoom Gantt Chart Web Part

Written by Wouter Baltus   // 15 December 2011   // 2 Comments

To autozoom your Gantt Chart add this script. You can also add the function to a button, so you don’t have to use the zoom in the ribbon.

WebPartWPQ2_JSGridController is the name of your Gantt Chart object. To see your objectname, right click in your browser, see the source and search in de bottom of your page to the JSON object. You can use more standard functions from the ribbon in this way. Check this jSON info!

$(document).ready(function() {
if(location.href.indexOf('NameOfYourPage.aspx') > 0)
{
  setTimeout("SetZoom()", 1000);
}
});

function SetZoom()
{
  WebPartWPQ2_JSGridController.ZoomOutGantt();
}


Similar posts

2 COMMENTS

  1. By takuan64, 16 May 2012

    Hello,

    thank you for your tip !
    I have a little question for you :
    How can I obtain the Gantt Chart object name programmatically ?

    Thanks in advance.

    Reply
    • By takuan64, 16 May 2012

      Auto-answer !
      Finally I use this :

      var _jsGridControl;
      ExecuteOrDelayUntilScriptLoaded(function () {
      var oldGanttControl = SP.GanttControl;
      SP.GanttControl = function () {
      oldGanttControl.call(this);
      var oldInit = this.Init;
      this.Init = function (jsGridControl, jsRawGridData, params) {
      oldInit.call(this, jsGridControl, jsRawGridData, params);
      DoCustomizations(jsGridControl);
      };
      };
      }, “SPGantt.js”);

      function DoCustomizations(grid) {
      _jsGridControl = grid;
      }

      function OnClientValueChanged(sender, args) {
      var oldValue = args.get_oldValue();
      var newValue = args.get_newValue();
      if (oldValue < newValue) { _jsGridControl.SetGanttZoomLevel(_jsGridControl.GetGanttZoomLevel() + 1);
      }
      else { _jsGridControl.SetGanttZoomLevel(_jsGridControl.GetGanttZoomLevel() – 1);
      }
      }

      Where function OnClientValueChanged is an event of a slider.

      Look on tomblog for more information : http://tomblog.insomniacminds.com/2011/07/09/sharepoint-2010-customizing-the-gantt-view-and-the-client-grid

      A+

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *