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.
|
If the reported issue persists, kindly share the simple issue reproducible sample, or reproduce a reported issue in the provided sample. It will be very helpful for us to validate the reported query at our end and provide the solution as early as possible
The problem appears to be with binding. I have already implemented the customer logic in the class. however, because I'm not getting the correct information in the Args, I can't do anything with it. The Args value is null. This indicates a binding issue with the grid. Moreover, there is no errors generated that indicate a problem, only that the data is not returned with a record is selected and edited in the grid. This problem is more difficult, and is the reason why I created the zip file for your use and review.
Thanks for the update,
We validated the query, but we are still unable to reproduce the reported issue
in our final version[20.0.3.60].Before proceeding further with your
requirement. kindly share the below details will be very helpful for us to
validate the reported query at our end and provide the solution as early as
possible.
It is with great pleasure to provide the non-functioning blazor grid application using the simple solution that has been shown on the previous replies. The focus of this is to determine why binding to a CSLA object does not function correctly. I have provided the classes, and necessary code for this application to run. It should be noted that this will provide days and days of shear fun and amusement--it is the only way to characterize the last 5 18 hour days trying to figure this out.
It is critically important that this basic grid functionality works. I have an enterprise application that is being developed and the use of Syncfusion blazor controls were selected because of the image and presentation. But unlike a beauty pageant, the controls must work.
I am so looking forward to the solution, work around, or fix--since it Christmas time.
I wish you the best and hope you're on hourly as this will take you to Dante's peak.
Warmest Regards,
Man-with-little-sleep.
We are currently Validating the reported query at our end and we will update the further details shortly. Until then we appreciate your patience.
I really appreciate you looking into this. Thank you so much.
Sorry for the inconvenience caused.
We are facing some difficulties in validating the reported
issue. We need some more time to validate the issue on our end. we will update the further
details shortly.
Until then we
appreciate your patience.
Good to hear your status update. Thank you for your continued support.
Sorry for the delay causing inconvenience.
After reviewing the reported issue, we have determined that the grid component
uses a T-value-based approach for data binding. This means that the data source
for the grid is expected to be a collection of objects with properties of type
T, and the grid will bind to the properties of these objects to display data in
the grid. This is the default behavior of the grid.
Regarding your issue using CreateInstanceDI
with a generic property in a CSLA project, we want to inform you that DataGrid does not have direct support for this feature. However, you can use
the ExpandoObject feature to bind the DataGrid to data and achieve your
requirement. For more information about ExpandoObject binding, please refer to
the following documentation:
https://blazor.syncfusion.com/documentation/datagrid/data-binding#expandoobject-binding
I am going to use the expondoObject to test this functionality. Did you folks get this to work with ExpandoObject with the project that was submitted? If so, please zip the file up so that I can see how you folks resolved the issue.
Thanks,
Kevin
We are sorry for the trouble this has caused.
We use expando object binding to test the possibility of a
requirement. We regret to inform you that your request cannot be fulfilled
using the expando object. As you are now closing the thread.
Please get back if you have any further questions
Why am I closing the thread? Why did you regret to inform me that my request cannot be fulfilled using the expando object class? How did you resolve the issue of the binding problem without testing it?
Thank you for reaching out to
us and providing the update. We apologize for any inconvenience this may have
caused.
We are currently again evaluating the feasibility of using the expando object or another approach to meet your requirements. As soon as we have a solution that meets your needs, we will prepare a sample and provide an update. In the meantime, we appreciate your patience and understanding.
Here is a link to ticket that had a solution to grid binding in csla framework. Can I see what the solution was
We have created a simple sample for using csla and provided access to the mentioned feedback. Please refer to the attached solution sample and feedback link for more information.
Feedback Link: https://www.syncfusion.com/feedback/16588/issue-occur-in-grid-while-binding-csla-framework-based-datasource
The sample project is from CSLA 5 and the release I'm using is 6. This is a big deal since I need control over creation of an object by passing the applicationContext into the classes. The solution provided still uses the static DataPortal.Create methodology which is no longer supported. I need to be on .NET 7 with EF Core 7.
I have been spending an inordinate amount of time trying to get the grid to work with CSLA. My issue is trying to find all the paths where a "new" invocation of an object is executed. It would appear that it occurs frequently and without the ability to prevent it. Additionally, I am unable to find the data once the edit dialog is closed, since it is not passed into the save method; is not saved; and appears unavailable. When the save method is executed, it again goes out to instantiate another accounting object. I have already created it, and I fail to see why this is occurring or how to stop it.
public async Task Save()
{
await AccountGrid.EndEditAsync(); <<goes and creates a new object.
}
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Add))
{
var item = await chartOfAccountPortal.CreateAsync();
Args.Data = item;
await AccountGrid.AddRecordAsync(item);
}
Based on your requirement, we suggest
referring them to an example sample available for their CSLA GitHub location.
Please see the You can create your own business logic and customize your
requirements at your end.
Reference:https://github.com/MarimerLLC/csla/tree/main/Samples