0

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).

Daniel Hjertholm
  • 177
  • 1
  • 2
  • 16
  • If this is `UpdatePanel` check this: https://stackoverflow.com/a/16990515/1498401 . If this is `js grid` check this: https://msdn.microsoft.com/en-us/library/office/ff681039(v=office.14).aspx – tinamou Apr 18 '18 at 15:40

1 Answers1

1

Here are my testing results [with Office 365 / SharePoint Online]. Try the checkbox using a button and/or one of the following browsers (where possible)  Added this script to the Content Editor web part. I seemed to have problems running this, but once it worked, I checked it against all four of the browsers I had installed.

MS Edge 40.15063.674.0  - won't run the script automatically. I added a button and the it will collapse entire list, and then expand the entire list. I keep hitting the button and it keeps expanding / collapsing the list

MS IE 11.1563.15063.0  - Runs with list collapsed (it works!). Pressing the button does nothing.

FireFox Quantum 64-bit (no version #)  - Runs with list collapsed (it works!). Pressing the button expands the list. Pressing it again selects the last collapse/expand item in the list.

Google Chrome 72.0.3626.109  - won't run the script automatically. Pressing the button collapses the list. Pressing the button again does nothing.

No other browsers installed or tested.

Button markup added:

<input type="button" value="Collapse Task List" onclick="doCollapseTaskList()">

Seems the script was written for IE.  Looks like someone would need to modify it to support multiple browsers.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574