|
<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();
}
}
} |
|
[_Host.cshtml]
<body>
…./////
<script src="_content/Microsoft.AspNetCore.ProtectedBrowserStorage/protectedBrowserStorage.js"></script>
</body>
|
|
[Startup.cs]
public void ConfigureServices(IServiceCollection services)
{
…./////
services.AddProtectedBrowserStorage();
} |
|
[Imports.razor]
@using Microsoft.AspNetCore.ProtectedBrowserStorage
[Index.razor]
@inject ProtectedSessionStorage ProtectedSessionStore
|
|
[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;
}
..///
}
|