Hide old tasks

Good afternoon,

I'm using the gantt sent the data in json.

Can I keep up with old tasks?

Thanks

3 Replies 1 reply marked as answer

KR Karthikeyan Raja Syncfusion Team December 2, 2020 11:59 AM UTC

Hi Thiago,

We can push the new JSON data and update the Gantt data source using dataSource property. Please refer the below code snippet,
 
var ganttChart = new ej.gantt.Gantt({ 
  dataSource: [ 
   //…… 
}); 
ganttChart.appendTo("#Default"); 
 
var updateBtn = new ej.buttons.Button(); 
updateBtn.appendTo("#update"); 
 
document.getElementById("update").addEventListener("click", function() { 
  var newData = { 
    TaskID: 5, 
    TaskName: "Project Estimation", 
    StartDate: new Date("04/02/2019"), 
    EndDate: new Date("04/21/2019"), 
    subtasks: [ 
      { 
        TaskID: 6, 
        TaskName: "Develop floor plan for estimation", 
        StartDate: new Date("04/04/2019"), 
        Duration: 3, 
        Progress: 50 
      }, 
      { 
        TaskID: 7, 
        TaskName: "List materials", 
        StartDate: new Date("04/04/2019"), 
        Duration: 3, 
        Progress: 50 
      }, 
      { 
        TaskID: 8, 
        TaskName: "Estimation approval", 
        StartDate: new Date("04/04/2019"), 
        Duration: 3, 
        Progress: 50 
      } 
    ] 
  }; 
  ganttChart.dataSource.push(newData); 
  ganttChart.refresh(); 
}); 
 
 
 
We have also prepared a sample for your reference. Please find the sample from below link,
Sample - https://stackblitz.com/edit/brpmyr?file=index.js

Please get back to us, If you need any further assistance.
 

Regards,
Karthikeyan Raja
 



TH Thiago December 3, 2020 09:00 PM UTC

Great solution.

Unfortunately for me this solution is not viable.
I need that when the json is being created inform that the task will be hidden

Example

dataSource: [
    {
      TaskID: 1,
      TaskName: "Project Initiation",
      StartDate: new Date("04/02/2019"),
      EndDate: new Date("04/21/2019"),
      subtasks: [
        {
          TaskID: 2,
          TaskName: "Identify Site location",
          StartDate: new Date("04/02/2019"),
          Duration: 4,
          Progress: 50
        },
        {
          TaskID: 3,
          TaskName: "Perform Soil test",
          StartDate: new Date("04/02/2019"),
          Duration: 4,
          Progress: 50,
          visible: false
        },
        {
          TaskID: 4,
          TaskName: "Soil test approval",
          StartDate: new Date("04/02/2019"),
          Duration: 4,
          Progress: 50
        }
      ]
Thanks


KR Karthikeyan Raja Syncfusion Team December 4, 2020 10:27 AM UTC

Hi Thiago,

We have analyzed your query. Is your requirement is to filter out the tasks which are set visible as false in the generated JSON and push the filtered data to Gantt then Please find the code snippet below,
 
var ganttChart = new ej.gantt.Gantt({ 
//….. 
}); 
ganttChart.appendTo("#Default"); 
 
document.getElementById("update").addEventListener("click", function() { 
  var newData = { 
    TaskID: 5, 
    TaskName: "Project Estimation", 
    StartDate: new Date("04/02/2019"), 
    EndDate: new Date("04/21/2019"), 
    subtasks: [ 
      { 
        TaskID: 6, 
        TaskName: "Develop floor plan for estimation", 
        StartDate: new Date("04/04/2019"), 
        Duration: 3, 
        Progress: 50, 
        Visible: true 
      }, 
      { 
        TaskID: 7, 
        TaskName: "List materials", 
        StartDate: new Date("04/04/2019"), 
        Duration: 3, 
        Progress: 50, 
        Visible: false 
      }, 
      { 
        TaskID: 8, 
        TaskName: "Estimation approval", 
        StartDate: new Date("04/04/2019"), 
        Duration: 3, 
        Progress: 50, 
        Visible: false 
      }, 
      { 
        TaskID: 9, 
        TaskName: "Product strength analsysis", 
        StartDate: new Date("04/06/2019"), 
        Duration: 1, 
        Progress: 50, 
        Visible: true 
      }, 
      { 
        TaskID: 10, 
        TaskName: "Research complete", 
        StartDate: new Date("04/08/2019"), 
        Duration: 3, 
        Progress: 50, 
        Visible: true 
      } 
    ] 
  }; 
  if (newData.subtasks.length > 0) { 
    for (var i = 0; i < newData.subtasks.length; i++) { 
      if (!newData.subtasks[i].Visible) { 
        newData.subtasks.splice(i, 1); 
        i--; 
      } 
    } 
  } 
  ganttChart.dataSource.push(newData); 
  ganttChart.refresh(); 
}); 
 
 
We have also prepared a sample for your reference. Please find the sample from below link,
Sample - https://stackblitz.com/edit/brpmyr-ywb4as?file=index.js
 
 
If above provided solution doesn’t meet your requirement, Please share more details on your requirement. So that we can assist you to achieve it. 
 
Regards,
Karthikeyan Raja
 


Marked as answer
Loader.
Up arrow icon