I have a SharePoint 2013 tasks list that is synced with a MS Project file. By default, the entire tasks list, with all the tasks, subtasks and sub-subtasks, is expanded. Which makes it pretty much useless when there are a few hundred or thousand tasks in the list. With the following code snippet found here I have been able to make the task list collapse:
<script type="text/javascript">
jQuery(document).ready(function($) {
(function($){
function doCollapseTaskList() {
$(".ms-commentcollapse-iconouter > img").each(function(){
$(this).click();
});
}
$(function() {
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
if (typeof asyncDeltaManager != "undefined")
asyncDeltaManager.add_endRequest(doCollapseTaskList);
else doCollapseTaskList();
},'SP.js');
});
})(jQuery);
});
</script>
But whenever i click the little checkbox next to a task, the list refreshes, and this time, it is expanded again. I don't understand why the script doesn't collapse the list after that refres. How can I make the script run after the refresh? Or is there any way to prevent the refresh after checking a checbox (while still having that check saved, of course).