I currently have a large project list that has numerous sub-tasks assigned to each main section. I'm looking to create a view that only displays the top level tasks.

I've looked at a previous question that was asked, providing the following solution:

jQuery('div[class="ms-vb  itx"]').find('span[style]').each(function(){

However it doesn't hide the sub-tasks for me. I'm currently testing said code in a script editor web-part and make a call to the Jquery library externally just before the script. Using:

Also tried various settings in the view itself, such as changing the folder settings but nothing allows you to hide sub-tasks out of the box.

Any help is greatly appreciated.

  • You edited the code Amal but there is no difference? How exactly did you use this code on your page, in a script editor? – cod3r_jim Oct 26 '17 at 12:15
  • I have only formatted the question.. its not the answer I placed – Amal Hashim Oct 26 '17 at 12:17

I tested the code in my online site. It actually works. Below are the steps I executed

  1. Open the Task List - Ex AllItems.aspx
  2. Edit Page
  3. Add a Script Editor Webpart
  4. Then used below code

        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', run);
    function run(){
        jQuery('div[class="ms-vb  itx"]').find('span[style]').each(function(){
            var left = Number(jQuery(this).css('margin-left').replace("px",""));
  • Spot on Amal. Hides the subtasks beautifully, great work. – cod3r_jim Oct 26 '17 at 13:20
  • Sadly it's not what I was looking for Amal, just testing it thoroughly now. This will only collapse the subtasks, they can still be viewed by clicking on the arrow beside the task name. Also it doesn't show all tasks, it only shows the tasks that contain subtasks. – cod3r_jim Oct 26 '17 at 13:55
  • I have made some mods.. please try new code – Amal Hashim Oct 26 '17 at 14:02
  • Perfect. Exactly what I needed. Thanks for your help. – cod3r_jim Oct 26 '17 at 14:10
  • Wonder if you could help me again Amal. I'm looking to do the exact same function, hide all subtasks and only show the top level of tasks but within a Gantt view. Thanks again. – cod3r_jim Oct 30 '17 at 10:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.