Avoiding Reflection-Based Full Property Iteration of Grid DataSource

  Hi,

  I'm Julian Mensch, a developer from Metegrity Inc. using a licensed version of Syncfusion's Blazor controls. We're relatively new to both Syncfusion and Blazor.

  We're trying to bind a list (IEnumerable) of our complex (proprietary) data objects to Syncfusion's SfGrid. This works great -- we can generate our own columns and so forth -- until we try to make the grid editable.

  In this case, we run into Syncfusion code trying to use Reflection to iterate the properties of our objects -- all the properties, not just the one indicated in GridColumn.Field values for our defined grid columns. This is really bad for our use case -- some properties throw exceptions based on the overall object state, and even if they didn't it would be terrible for performance.

  Specifically, it seems like there's an internal function, CloneRowData, which tries to both get and set all of the DataSource object's properties. We need to find a way to limit or prevent it from doing this. Can anyone from Syncfusion give me some guidance in how to achieve this? We want to limit this to only the properties specifically mentioned as grid column fields. A way to override or replace the default CloneRowData code with our own would solve this as well.

  I've attached a Visual Studio screencap of the stack trace showing CloneRowData.

  Thanks for any insight you can offer!

Attachment: CloneRowData_StackTrace_766c1527.zip

3 Replies

RS Renjith Singh Rajendran Syncfusion Team March 26, 2021 11:16 AM UTC

Hi Julian, 

Greetings from Syncfusion support. 

We have analyzed the reported scenario. We need the following details to proceed further on this and provide you a suggestion as early as possible. 

  1. Share the complete Grid model class codes.
  2. Share the details of the exception you are facing while editing in Grid.
  3. Share a video demo showing the replication procedure of the problem you are facing.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

And also we suggest you to refer the below documentation and check this scenario for handling the editing action using events. 

Regards, 
Renjith R 



JM Julian Mensch April 16, 2021 09:58 PM UTC

  Hi,

  I'm sorry it's taken me so long to reply to this. I can't share the actual source code, nor can I produce videos on my dev computer -- but I can provide a very simple sample Razor component that demonstrates the issue. I'm pasting it below, and also including it as a .ZIP file along with a screencap showing the exception (which occurs when you open the component and try to edit any cell in the grid).

  The core issue is that the SfGrid is trying to touch all properties of the model class, not just the ones referenced as GridColumn objects. This works fine in simple test code, but in practice data objects often have properties that for various reasons cannot be read or set at all times. Since the SfGrid isn't set up to do anything with PropertyC, it should not try to touch PropertyC.

  Your suggestions for BeforeAdd and CellEdit are useful in the case where the model class does not have a parameterless public constructor, but they don't seem to help for the case where the model class has properties that the code should not touch.

@page "/itererr"
@using Syncfusion.Blazor.Grids

<h3>IterationPropertyError</h3>


@if (Data == null)
{
  <p><em>Loading...</em></p>
}
else
{

<SfGrid DataSource="@Data">
  <GridColumns>
    <GridColumn HeaderText="Column A" Field="PropertyA" />
    <GridColumn HeaderText="Column B" Field="PropertyB" />
    <!-- Explicitly note that there is no reference to PropertyC, so it should
         not be touched. -->
  </GridColumns>
  <GridEditSettings AllowAdding="true"
                      AllowDeleting="true" ShowDeleteConfirmDialog="false"
                      AllowEditing="true" AllowEditOnDblClick="true" />

</SfGrid>
}

@code {

  public ModelClass[] Data = new ModelClass[]
    { new ModelClass("A1","B1","C1") ,
      new ModelClass("A2","B2","C2") };

  public class ModelClass
    {
      private string _a, _b, _c;
      public ModelClass(string A, string B, string C)
        { _a = A; _b = B; _c = C; }
      public ModelClass()
        { _a = null; _b = null; _c = null; }
      public string PropertyA
        { get { return _a; }
          set { _a = value; } }
      public string PropertyB
        { get { return _b; }
          set { _b = value; } }
      public string PropertyC
        { get { throw new Exception("This property is inaccessible at present."); }
          set { throw new Exception("This property is inaccessible at present.");  } }
    }
}


Attachment: IterationPropertyError_23237126.zip


RS Renjith Singh Rajendran Syncfusion Team April 19, 2021 11:16 AM UTC

Hi Julian, 

We have confirmed it as a bug and logged the defect report “Need to provide support to skip object cloning while editing” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our weekly release which is expected to be rolled out by the end of May, 2021.  
       
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.       

Regards, 
Renjith R 



Loader.
Up arrow icon