SfGantt - refresh diagram

Hi there,

is it possible to keep the manually opened tasks open after calling .Refresh?

e.g.
First I collapse all tasks.
Then I open parent task ID 3015 and 3042 to show their childs.
Then I press "Refresh Gannt" (calls MyGantt.Refresh();).
Result: all parent-tasks are opened and not only my two selected ones (cause of default ).

But it would be more elegant to refresh the gantt (e.g. read newest data from SQL-Server and get changes of names or durations made by 3rd person) without changing the tree-node.


Any idea?

Cheers,
Volker

5 Replies 1 reply marked as answer

PP Pooja Priya Krishna Moorthy Syncfusion Team July 3, 2020 03:13 PM UTC

Hi Volker, 
We can maintain the expand status of records even after refreshing by updating expand status of record in Collapsed and Expanded event using UpdateRecordByID method.  
Please find the below code example. 
<SfGantt @ref="Gantt" > 
//... 
        <GanttTaskFields Id="Id" ExpandState="IsExpand" > 
        </GanttTaskFields> 
        <GanttEvents TValue="Table" Expanded="Expanded" Collapsed="Collapsed"></GanttEvents> 
    </SfGantt> 
    @code { 
        public SfGantt<Table> Gantt; 
        public void Collapsed(ICollapsingEventArgs<Table> args) 
        { 
            this.Gantt.UpdateRecordByID(new Table() { Id = args.Data.TaskData.Id, IsExpand = false }); 
        } 
        public void Expanded(ICollapsingEventArgs<Table> args) 
        { 
            this.Gantt.UpdateRecordByID(new Table() { Id = args.Data.TaskData.Id, IsExpand = true }); 
        } 
    } 


public override object BatchUpdate(DataManager dm, object changedRecords, object addedRecords, object deletedRecords, string keyField, string key, int? dropIndex) 
    { 
        //… 
        if (changed != null) 
        { 
            for (var i = 0; i < changed.Count(); i++) 
            { 
                //… 
                result.IsExpand = value.IsExpand; 
                Service.SaveChanges(); 
            } 
        } 
} 


Currently, we are facing issue in particular case, we logged bug report for this. The status can be tracked from below feedback link. 
We will fix this issue and the fix will be included in our upcoming weekly patch release which is expected to be rolled out on July 15, 2020. 
Until then we appreciate your patience. 

Regards, 
Pooja K 



VO Volker July 15, 2020 07:13 AM UTC

Hi Pooja,

hm, this isn't a robust solution:

Think about a scenario, where two persons work on two different browsers/desktops in the backend with the same gantt-diagram data.
Everytime somebody opens a parent-task, the IsExpanded-state gets stored in the table (SQL-server).
When the other user refreshes his gantt, a parent-task in his browser gets magically opened although he didn't click on any task...

Any better idea to cache the opened tasks for Gantt-diagramm for each client-browser?

Cheers,
Volker


LG Logeswari Gopalakrishnan Syncfusion Team July 22, 2020 03:14 AM UTC

Hi Volker, 
Thanks for your patience. 
We have achieved your requirement by persist collection using SessionStorage. To use SessionStroage we need to install Microsoft.AspNetCore.ProtectedBrowserStorage . Please refer the following steps. 
  1. To add Microsoft.AspNetCore.ProtectedBrowserStorage package,  please refer the following link.
 
  1. Need to add following script in _Host.cshtml.
 
[_Host.cshtml] 
 
<body> 
….///// 
 
    <script src="_content/Microsoft.AspNetCore.ProtectedBrowserStorage/protectedBrowserStorage.js"></script> 
</body> 
 
 
  1. To add SessionStorage service to service collection, need to call AddProtectedBrowserStorage method in ConfigureServices of Startup.cs.
 
[Startup.cs] 
 
public void ConfigureServices(IServiceCollection services) 
        { 
…./////             
          services.AddProtectedBrowserStorage(); 
        } 
 
  1. Component that requires loading or saving data to browser storage, use @inject to inject an instance of ProtectedSessionStorage.
 
[Imports.razor] 
 
@using Microsoft.AspNetCore.ProtectedBrowserStorage 
 
[Index.razor] 
 
@inject ProtectedSessionStorage ProtectedSessionStore 
 
 
  1. Here, we persist storage data (Expanded id/Collapsed id) in Expanded and Collapsed event using method ProtectedSessionStore.SetAsync. Based on these values, we update DB with property IsExpand in ReadAsync method. Please find the below code snippet.
 
[Index.razor] 
 
@inject ProtectedSessionStorage ProtectedSessionStore 
 
@code {  
    public List<int> ExpandData = new List<int>(); 
    public List<int> CollapseData = new List<int>(); 
    public SfGantt<Table> Gantt; 
 
   public async void Collapsed(ICollapsingEventArgs<Table> args) 
    { 
        if (!args.Data.Expanded && !CollapseData.Contains(args.Data.TaskData.Id)) 
        { 
            CollapseData.Add(args.Data.TaskData.Id); // Push the Collapsed record id’s 
        } 
        // Set these values to session storage using variable called collapseid 
        await ProtectedSessionStore.SetAsync("collapseid", CollapseData); 
        //Get the expandid collection from sessionstorage if exists 
        ExpandData = await ProtectedSessionStore.GetAsync<List<int>>("expandid"); 
        if (ExpandData != null) 
        { 
            ExpandData.Remove(args.Data.TaskData.Id); // Remove if collapseid is already present in expandid collection 
            await ProtectedSessionStore.SetAsync("expandid", ExpandData); 
        } 
    } 
    public async void Expanded(ICollapsingEventArgs<Table> args) 
    { 
        if (args.Data.Expanded && !ExpandData.Contains(args.Data.TaskData.Id)) 
        { 
            ExpandData.Add(args.Data.TaskData.Id); // Push the Expanded record id’s 
        } 
        // Set these values to session storage using variable called expandid 
        await ProtectedSessionStore.SetAsync("expandid", ExpandData); 
        //Get the collapseid collection from sessionstorage if exists 
        CollapseData = await ProtectedSessionStore.GetAsync<List<int>>("collapseid"); 
        if (CollapseData != null) 
        { 
            CollapseData.Remove(args.Data.TaskData.Id); // Remove if expandid is already present in collpaseid collection 
            await ProtectedSessionStore.SetAsync("collapseid", CollapseData); 
        } 
    }} 
 
 
[CustomComponent.razor] 
 
@inject ProtectedSessionStorage ProtectedSessionStore 
../// 
 
@code { 
 
    public List<int> ExpandId = new List<int>(); 
 
    public List<int> CollapseId = new List<int>(); 
 
    // Performs data Read operation 
    public async override Task<object> ReadAsync(DataManagerRequest dm, string key = null) 
    { 
        // Get expandid collection from sessionstorage 
        ExpandId = await ProtectedSessionStore.GetAsync<List<int>>("expandid"); 
        // Get collapseid collection from sessionstorage 
        CollapseId = await ProtectedSessionStore.GetAsync<List<int>>("collapseid"); 
       // If expandid present , set IsExpand property as true. 
        if (ExpandId != null && ExpandId.Count > 0) 
        { 
            for (var i = 0; i < ExpandId.Count; i++) 
            { 
                Table result = Service.Table.Where(or => or.Id == ExpandId[i]).FirstOrDefault(); 
                result.IsExpand = true; 
                Service.SaveChanges(); 
            } 
        } else if (ExpandId == null) 
        { 
            Table result = Service.Table.Where(or => or.IsExpand == true).FirstOrDefault(); 
            if (result != null) 
            { 
                result.IsExpand = false; 
                Service.SaveChanges(); 
            } 
        } else if (CollapseId != null && CollapseId.Count > 0) 
        { 
            for (var i = 0; i < CollapseId.Count; i++) 
            { 
                Table result = Service.Table.Where(or => or.Id == CollapseId[i]).FirstOrDefault(); 
                result.IsExpand = false; 
                Service.SaveChanges(); 
            } 
        } 
        int count = Service.Table.Cast<Table>().Count(); 
        return dm.RequiresCounts ? new DataResult() { Result = Service.Table, Count = count } : (object)Service.Table; 
    } 
../// 
} 
 
 
We have prepared sample for this. Please find it from below link. 
Please let us know, if you need further details on this. 
Regards, 
Logeswari G 


Marked as answer

VO Volker July 23, 2020 01:01 PM UTC

cool solution path.
Will implement it and let you know if everything is done so far.

Thank you again, Logeswari!
Great job!

Cheers,
Volker


LG Logeswari Gopalakrishnan Syncfusion Team July 24, 2020 05:40 AM UTC

Hi Volker, 
Most welcome.  
We will wait to hear from you. 
Please get back to us if you have further queries.  
Regards, 
Logeswari G 


Loader.
Up arrow icon