<SfGantt ID="GanttExport" TValue="Table" Height="450px" Width="700px"
…///
<GanttColumns>
<GanttColumn Field=@nameof(Table.Id) Width="100" Visible="false"></GanttColumn>
</GanttColumns>
</SfGantt> |
S.No |
Queries |
Syncfusion Comments | |
1. |
We must transfer your domain models to SQL Server entities: |
By using hierarchal data , we can not perform operations on server-side. So we can use self-reference data binding. | |
2 |
We must be able to use all the functions of your context menu, but this time targeting to SQL-Server using EF Core: |
Currently we are working on this. We will provide the further details on June 8,2020. | |
3 |
We must be able to manage resources via checkboxes and send it to SQL-Server using EF Core: |
We can manage resources using dialog edit and changes are send to SQL- sever by changing collection of resources to string. Please find the below code snippet.
|
public override object BatchUpdate(DataManager dm, object changedRecords, object addedRecords, object deletedRecords, string keyField, string key, int? dropIndex)
{
List<GanttData> addRecord = addedRecords as List<GanttData>;
…//////
if (addRecord != null)
{
for (var i = 0; i < addRecord.Count(); i++)
{
var added = addRecord[i];
var newRecord = new Table {
Id = added.Id,
Name = added.Name,
Sdate = added.Sdate,
Edate = added.Edate,
Progress = added.Progress,
ParentId = added.ParentId,
ResourceId = added.ResourceId == null ? "" : UpdateResourceID(added.ResourceId)
};
db.Add<Table>(newRecord);
db.SaveChanges();
}
}
return (new { addedRecords = addRecord, changedRecords = changed, deletedRecords = deleteRecord });
} |
S.no |
Hierarchical data binding |
self-referential data binding | ||
1. |
In hierarchical data binding subtasks or child tasks collections are identified by using Child property. |
Gantt can be rendered from self-referential data structures, by mapping the Id and ParentID fields. | ||
2. |
DataSouce:
|
DataSource:
| ||
3. |
TaskFields:
|
TaskFields:
| ||
4. |
Sample link for Hierarchical data binding:
|
Sample link for Flat data:
|
USE [Gantt-Test]
GO
CREATE TABLE [dbo].[GanttTasks](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](100) NULL,
[Sdate] [datetime] NULL,
[Edate] [datetime] NULL,
[Progress] [nchar](10) NULL,
[ParentId] [int] NULL,
[Duration] [nchar](10) NULL,
[Dependency] [nvarchar](100) NULL,
CONSTRAINT [PK_GanttTasks] PRIMARY KEY CLUSTERED
( [Id] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] )
ON [PRIMARY]
GO
[masterContext.cs]
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.Build();
optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
}
}
[app.settings.json]
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\MSSQLLOCALDB; Database=MT; Trusted_Connection=True; MultipleActiveResultSets=true"
}
}
|
[Index.razor]
<SfGantt ID="GanttExport" TValue="Table" Height="450px" Width="700px">
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<CustomComponent></CustomComponent>
</SfDataManager>
</SfGantt>
[CustomComponent.razor]
@inherits DataAdaptor<masterContext>
@code {
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
int count = Service.Table.Cast<Table>().Count();
return dm.RequiresCounts ? new DataResult() { Result = Service.Table, Count = count } : (object)Service.Table;
}
// Performs CRUD operation
public override object BatchUpdate(DataManager dm, object changedRecords, object addedRecords, object deletedRecords, string keyField, string key, int? dropIndex)
{
List<Table> addRecord = addedRecords as List<Table>;
List<Table> changed = changedRecords as List<Table>;
List<Table> deleteRecord = deletedRecords as List<Table>;
if (changed != null)
{
for (var i = 0; i < changed.Count(); i++)
{
var value = changed[i];
Table result = Service.Table.Where(or => or.Id == value.Id).FirstOrDefault();
result.Id = value.Id;
result.Name = value.Name;
result.Sdate = value.Sdate;
result.Edate = value.Edate;
result.Duration = value.Duration;
result.Progress = value.Progress;
Service.SaveChanges();
}
}
if (deleteRecord != null)
{
for (var i = 0; i < deleteRecord.Count(); i++)
{
Service.Table.Remove(Service.Table.Where(or => or.Id == deleteRecord[i].Id).FirstOrDefault());
Service.SaveChanges();
}
}
if (addRecord != null)
{
for (var i = 0; i < addRecord.Count(); i++)
{
Service.Table.Add(addRecord[i] as Table);
Service.SaveChanges();
}
}
return (new { addedRecords = addRecord, changedRecords = changed, deletedRecords = deleteRecord });
}
}
|
[FetchData.razor]
@using GanttEF.Models
@if (Table is null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Sdate</th>
<th>Edate</th>
</tr>
</thead>
<tbody>
@foreach (var task in Table)
{
<tr>
<td>@task.Id</td>
<td>@task.Name</td>
<td>@task.Sdate</td>
<td>@task.Edate</td>
</tr>
}
</tbody>
</table>
}
@code{
[Inject]
protected masterContext db { get; set; }
IQueryable<Table> Table;
protected override void OnInitialized()
{
Table = db.Table;
}
} |