Sharepoint script webpart in Gantt not working

266 Views Asked by At

i couldn't understand why, but i built gantt chart from ms project on sharepoint, with many subtask, and I would like to hide subtasks by default.

Unfortunately, any script that i put above my gantt chart doesn't work and produce anything...

i tried every type of link , nothing work... i couldn't understand the problem.. i tried what is explained here, with that code : Why is this jQuery not working on my Sharepoint page? but nothing work enter image description here

<script
      src="https://code.jquery.com/jquery-3.2.1.min.js"
      integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
      crossorigin="anonymous"></script>

<script>
jQuery(document).ready(function(){
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', run);
});

function run(){
    jQuery('div[class="ms-vb  itx"]').find('span[style]').each(function(){
        if(jQuery(this).css('margin-left')!="0px"){
            jQuery(this).parent().parent().parent().hide();
        }
    });
}
</script>

thanks

2

There are 2 best solutions below

0
On

The JSON formatting below for your reference, it also works in modern task list.

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "style": {
        "display": "table",
        "width": "100%"
    },
    "attributes": {
        "class": "=if(@currentField == 'No Issues', 'sp-field-severity--good', if(@currentField == 'Inactive', 'sp-field-severity--low', if(@currentField == 'Warning', 'sp-field-severity--warning', if(@currentField == 'In Review', 'sp-field-severity--severeWarning', 'sp-field-severity--blocked')))) + ' ms-fontColor-neutralSecondary'"
    },
    "children": [
        {
            "elmType": "span",
            "style": {
                "padding": "0 4px",
                "display": "table-cell",
                "vertical-align": "middle",
                "width":"16px"
            },
            "attributes": {
                "iconName": "=if(@currentField == 'No Issues', 'CheckMark', if(@currentField == 'Inactive', 'Forward', if(@currentField == 'In Review', 'Error', if(@currentField == 'Warning', 'Warning', 'ErrorBadge'))))"
            }
        },
        {
            "elmType": "span",
            "txtContent": "@currentField",
            "style": {
                "display": "table-cell",
                "font-weight": "bold",
                "padding-left": "10px",
                "vertical-align": "middle"
            }
        }
    ]
}

enter image description here

0
On

I reinstalled everything on a new site and it works now... very strange issue.

I would like to know if its also possible to change formating in Task listing view :

{
  "$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
  "elmType": "div",
  "attributes": {
    "class": {
      "operator": "?",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "@currentField",
            "No Issues"
          ]
        },
        "sp-field-severity--good",
        {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "@currentField",
                "Inactive"
              ]
            },
            "sp-field-severity--low",
            {
              "operator": "?",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    "@currentField",
                    "Warning"
                  ]
                },
                "sp-field-severity--warning",
                {
                  "operator": "?",
                  "operands": [
                    {
                      "operator": "==",
                      "operands": [
                        "@currentField",
                        "In Review"
                      ]
                    },
                    "sp-field-severity--severeWarning",
                    "sp-field-severity--blocked"
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding-left": "4px"
      },
      "attributes": {
        "iconName": {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "@currentField",
                "No Issues"
              ]
            },
            "CheckMark",
            {
              "operator": "?",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    "@currentField",
                    "Inactive"
                  ]
                },
                "Forward",
                {
                  "operator": "?",
                  "operands": [
                    {
                      "operator": "==",
                      "operands": [
                        "@currentField",
                        "In Review"
                      ]
                    },
                    "Error",
                    {
                      "operator": "?",
                      "operands": [
                        {
                          "operator": "==",
                          "operands": [
                            "@currentField",
                            "Warning"
                          ]
                        },
                        "Warning",
                        "ErrorBadge"
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField",
      "style": {
        "padding-left": "10px",
        "font-weight": "bold"
      }
    }
  ]
}

with something like that (this code is working with list but not tasks listing app, cant see why)