0

I have a gantt chart and I want to scroll to today's date. I've found the code online but I've not found a way to delay the execution of the code until after the chart is rendered. I've currently hacked it using the settTimeout method but I don't like this solution. Does anyone know if there is an Oncomplete event or something similar for the gantt chart?

Here's my code at the moment. The executeOrDelayUntilScriptLoaded does not wait until the gantt chart has loaded so I've added a second delay. Works but feels hacky

SP.SOD.executeOrDelayUntilScriptLoaded(ScrollToToday,'jsgrid.js');

function ScrollToToday(){
setTimeout(function(){
$("div[id$='_ListViewWebPartJSGrid']")[0].jsgrid.ScrollGanttToDate(new Date());
}, 1000);
}
  • The scriptdelay does just that.. wait for jsgrid.js. The Gannt chart does not fire a loaded event. So all you can do is rewrite your timeout to a shorter loop and check if the DOM element exists. FYI. SharePoint has its own _SPYield declared, which is a wrapper around the timeout function – Danny '365CSI' Engelman Jan 11 '16 at 12:47
  • @DannyEngelman thanks dude. In the end i created a setinterval method and check if teh function is available. Seems to work ok. Bummed that there isnt a loaded event for the gantt chart though – Richard Banks Jan 11 '16 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.