I am trying to use the grid. I am using CSLA for my business objects. I cannot use the Activator.CreateInstance----ever. I have to use a method on the class via a portal. This is really simple stuff, but yet simply not working:
<SfGrid DataSource="@vm.Model" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<GridEvents TValue="ChartOfAccountInfoPersist" OnActionBegin="ActionBegin"></GridEvents>
<GridSelectionSettings Type="SelectionType.Single" Mode="Syncfusion.Blazor.Grids.SelectionMode.Row"></GridSelectionSettings>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" ShowDeleteConfirmDialog="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(ChartOfAccount.Id) HeaderText="Id" TextAlign="TextAlign.Left" AllowEditing="false" Width="160"></GridColumn>
<GridColumn Field=@nameof(ChartOfAccount.AccountNumber) HeaderText="Account Number" TextAlign="TextAlign.Left" Width="160"></GridColumn>
<GridColumn Field=@nameof(ChartOfAccount.Description) HeaderText="Description" TextAlign="TextAlign.Left" Width="160"></GridColumn>
<GridColumn Field=@nameof(ChartOfAccount.ChargeOfAccountParentId) HeaderText="Parent" TextAlign="TextAlign.Left" Width="160"></GridColumn>
</GridColumns>
</SfGrid>
public void ActionBegin(ActionEventArgs<ChartOfAccountInfoPersist> arg)
{
//Handles add operation
if (arg.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Add))
{
CompanyEmployeeCriteria criteria = new CompanyEmployeeCriteria(1, 1);
arg.Data = chartOfAccountPortal.Create(criteria);
}
This if statement is never true.
if (arg.RequestType.Equals(Syncfusion.Blazor.Grids.Action.BeginEdit))
{
CompanyEmployeeCriteria criteria = new CompanyEmployeeCriteria(1, 1);
arg.Data = chartOfAccountPortal.Create(criteria);
arg.Data.AccountNumber = arg.RowData.AccountNumber;
arg.Data.CompanyKey = arg.RowData.CompanyKey;
arg.Data.Description = arg.RowData.Description;
arg.Data.ChartOfAccountTypeCd = arg.RowData.ChartOfAccountTypeCd;
}
} <-- when the this executes, it calls Activator.CreateInstance which will return null on the object. You can see in the code that I have already created the object and I'm attempting to assign it back to the grid. But, the arg.RowData is null too.
Questions:
How do I prevent Activator.CreateInstance from invoking?
Why is arg.RequestType.Equals(Syncfusion.Blazor.Grids.Action.BeginEdit)) not t
Hi Kevin,
Greetings from Syncfusion support.
We could see that in your shared code snippet you have not enabled IsPrimaryKey property. We would like to inform you that CRUD operation in Grid will take place only based on the unique PrimaryKey column value. So IsPrimaryKey property must be enabled to any one of the unique valued column defined in grid. Only based on primary key value, the CRUD will be properly performed in Grid. So kindly check the reported issue after using IsPrimaryKey for an unique column.
Kindly get back to us if you still face difficulties or if you have further queries at your end.
Regards,
Monisha
Are you sure? Here is the code snippet that has the primary key identified. I have not changed this.
<GridColumn Field=@nameof(ChartOfAccount.Id) IsPrimaryKey="true" HeaderText="Id" TextAlign="TextAlign.Left" AllowEditing="false" Width="160"></GridColumn>
<form class="form-horizontal" method="post">
<div>
<SfGrid @ref=Grid DataSource="@vm.Model" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<GridEvents TValue="ChartOfAccountInfoPersist" OnActionBegin="ActionBeginHandler" OnActionComplete="ActionCompleteHandler"></GridEvents>
<GridSelectionSettings Type="SelectionType.Single" Mode="Syncfusion.Blazor.Grids.SelectionMode.Row"></GridSelectionSettings>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" ShowDeleteConfirmDialog="true"></GridEditSettings>
<GridTemplates>
<EmptyRecordTemplate>
<span>Loading Data.</span>
</EmptyRecordTemplate>
</GridTemplates>
<GridColumns>
<GridColumn Field=@nameof(ChartOfAccount.Id) IsPrimaryKey="true" HeaderText="Id" TextAlign="TextAlign.Left" AllowEditing="false" Width="160"></GridColumn>
<GridColumn Field=@nameof(ChartOfAccount.AccountNumber) HeaderText="Account Number" TextAlign="TextAlign.Left" Width="160"></GridColumn>
<GridColumn Field=@nameof(ChartOfAccount.Description) HeaderText="Description" TextAlign="TextAlign.Left" Width="160"></GridColumn>
<GridColumn Field=@nameof(ChartOfAccount.ChargeOfAccountParentId) HeaderText="Parent" TextAlign="TextAlign.Left" Width="160"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</form>
Hope you're having a good day :-)
Thanks
for update
We created a simple sample based on the reported issue while performing a
normal edit action, but the reported issue did not occur at our end. We would
also like to inform you that Grid uses Activator.CreateInstanceTValue>() to
create or clone new record instances during add and edit operations, so the
model class and any referenced complex type classes must have parameter less constructors
defined. In
some cases, custom logic is required to create a new object, or a new object
instance cannot be created using Activator.CreateInstanceTValue> (). In such
cases, you can manually provide model object instances via events.
Please
see the attached screenshots and sample solutions for your reference.
1. Triggered before editing the operation image.
|
2. Args.RowData received the image shown below.
|