Data is not saved when Grid.EndEditAsync() is called.

I am having problems getting the data to save after Adding/Editing a row. I am using the DataGrid with a Custom Adaptor and a Dialog to edit the data. On Executing Grid.EndEditAsync() nothing seems to happen. The breakpoint hits the  Grid.EndEditAsync() but not the UpdateAsync method in the DataAdaptor.




Attachment: Images_519213fe.rar

3 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team August 22, 2024 12:23 PM UTC

Hi John Groome,

Based on the reported issue, it seems that the IsPrimaryKey property is not enabled for the unique grid column in your code. When using CRUD operations in the grid, you should ensure that the primary key column contains unique values by setting the IsPrimaryKey property to true. This behavior is the default setting for the grid, so we recommend that you ensure the primary column contains unique values when adding data. Kindly refer to the attached code snippet and simple sample for your reference.

<GridColumns>

     <GridColumn Field="@nameof(ImageGridView.Keywords)" IsPrimaryKey =”true” HeaderText="Keywords" TextAlign="TextAlign.Left" Width="80"></GridColumn>

     <GridColumn Field="@nameof(ImageGridView.ImageName)" HeaderText="Image Name" TextAlign="TextAlign.Left" Width="100"></GridColumn>

     <GridColumn Field="@nameof(ImageGridView.Image)" HeaderText="Image" TextAlign="TextAlign.Center" Width="100">

         <Template>

             @{

                 imagerecord = (context as ImageGridView);

                 LoadImage();

                 <div class="image">

                     <img src="@imagesrc" width="50" height="50"/>

                 </div>

             }

         </Template>

     </GridColumn>

     <GridColumn Field="@nameof(ImageGridView.ImageDate)" HeaderText="Image Date" Type="ColumnType.DateOnly" TextAlign="TextAlign.Center" Width="50"></GridColumn>

     <GridColumn Field="@nameof(ImageGridView.FileName)" HeaderText="File Name" TextAlign="TextAlign.Left" Width="100"></GridColumn>

     <GridColumn Field="@nameof(ImageGridView.Active)" HeaderText="Active" TextAlign="TextAlign.Center" Width="50">

         <Template>

             @{

                 var image = (context as ImageGridView);

                  <div class="template_checkbox">

                     @if (image.Active)

                     {

                         <input type="checkbox" checked />

                     }

                     else

                     {

                         <input type="checkbox" />

                     }

                 </div>

             }

         </Template>

     </GridColumn>

</GridColumns>



Note:

To define the primary key, set IsPrimaryKey to true in a particular column whose value is unique.


Documentation: https://blazor.syncfusion.com/documentation/datagrid/editing


Sample:https://blazorplayground.syncfusion.com/embed/LZBptFBLrWGrKobn?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

Regards,
Prathap Senthil


Marked as answer

JG John Groome August 23, 2024 06:56 AM UTC

Thank you. That fixed the problem.



PS Prathap Senthil Syncfusion Team August 26, 2024 01:26 PM UTC

Thanks for the update,


We are happy to hear that the provided information was helpful. We are closing the forum now.


Loader.
Up arrow icon