Issue with custom adaptor component
Hi
I have created a custom adaptor razor component so I can specify the crud activities of my gantt chart and also easily access an injected HTTPClient. At present very basic just to test...
@using Syncfusion.Blazor;
@using Syncfusion.Blazor.Data;
@using Newtonsoft.Json
@using haProjectsSuite.Shared.ItemObjects
@using System.Net.Http
@inject HttpClient client
@inherits DataAdaptor<ProjectPlanItem>
<CascadingValue Value="@this">
@ChildContent
</CascadingValue>
@code {
[Parameter]
[JsonIgnore]
public RenderFragment ChildContent { get; set; }
// Performs data Read operation
public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null)
{
int ProjectPlanID = 1;
int InstanceID = 2;
IEnumerable<ProjectPlanItem> DataSource = await client.GetFromJsonAsync<IEnumerable<ProjectPlanItem>>("https://{URL}");
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
// Sorting
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<ProjectPlanItem>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
// Performs BatchUpdate operation
public override async Task<object> BatchUpdateAsync(DataManager dm, object Changed, object Added, object Deleted, string KeyField, string Key, int? dropIndex)
{
int ProjectPlanID = 1;
int InstanceID = 2;
if (Changed != null)
{
await client.PostAsJsonAsync<IEnumerable<ProjectPlanItem>>("https://{URL}", (IEnumerable<ProjectPlanItem>)Changed);
}
if (Added != null)
{
await client.PostAsJsonAsync<IEnumerable<ProjectPlanItem>>("https://{URL}", (IEnumerable<ProjectPlanItem>)Added);
}
if (Deleted != null)
{
foreach (var rec in (IEnumerable<ProjectPlanItem>)Deleted)
{
await client.DeleteAsync("https://{URL}");
}
}
return (object)await client.GetFromJsonAsync<IEnumerable<ProjectPlanItem>>("https://{URL}");
}
}
The adaptor is set up on the gantt chart as follows...
<SfGantt ID="GanttExport" TValue="ProjectPlanItem" Width="100%" Height="700px"
Toolbar="@(new List<string>() { "Add", "Edit", "Update", "Delete", "Cancel", "ExpandAll", "CollapseAll" })">
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<GanttAdaptor></GanttAdaptor>
</SfDataManager>
<GanttColumns>
<GanttColumn Field=@nameof(ProjectPlanItem.ID) Width="100"></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.Name) Width="250"></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.StartDate)></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.EndDate)></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.Duration)></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.DurationUnit)></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.Progress)></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.SubItemOf)></GanttColumn>
<GanttColumn Field=@nameof(ProjectPlanItem.Predecessor)></GanttColumn>
</GanttColumns>
<GanttEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" AllowTaskbarEditing="true" ShowDeleteConfirmDialog="true" NewRowPosition="RowPosition.Child"></GanttEditSettings>
<GanttTimelineSettings>
<GanttTopTierSettings Unit="TimelineViewMode.Week" Format="MMM dd, y"></GanttTopTierSettings>
<GanttBottomTierSettings Unit="TimelineViewMode.Day"></GanttBottomTierSettings>
</GanttTimelineSettings>
<GanttTaskFields Id="ID" Name="Name" StartDate="StartDate" EndDate="EndDate" Progress="Progress"
ParentID="SubItemOf" Dependency="Predecessor" Duration="Duration" DurationUnit="DurationUnit"></GanttTaskFields>
</SfGantt>
This loads the data and displays the gantt chart fine but errors on the add edit and delete functions.
The following is an example of the the error arising when trying to delete a record...
Uncaught (in promise) TypeError: Cannot read property 'ganttProperties' of null
at e.removeAddedRecord (gantt-3452e3.min.js:1)
at gantt-3452e3.min.js:1
| e.removeAddedRecord | @ | gantt-3452e3.min.js:1 | |
| (anonymous) | @ | gantt-3452e3.min.js:1 | |
| Promise.catch (async) | |||
| (anonymous) | @ | gantt-3452e3.min.js:1 | |
| e.notify | @ | syncfusion-blazor.min.js:1 | |
| e.trigger | @ | syncfusion-blazor.min.js:1 | |
| e.addRecord | @ | gantt-3452e3.min.js:1 | |
| e.initiateDialogSave | @ | gantt-3452e3.min.js:1 | |
| e.buttonClick | @ | gantt-3452e3.min.js:1 |
any thoughts on what is happening and how it might be resolved?
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
PE
Punniyamoorthi Elangovan
Syncfusion Team
November 3, 2020 03:34 AM UTC
Hi Matthew,
Thank you for contacting Syncfusion support.
We have analyzed your requirement and code snippet. We cannot able to reproduce the issue from our end. We have prepared the sample for your reference with custom adaptor support. We suspect the issue may occurred when the new added record not inserted properly to data base. Please find the sample from below link
Regards,
Punniyamoorthi
Marked as answer
SIGN IN To post a reply.