Problem with Using the AutoFill Feature in DropDownList in Grid Batch Mode

I'm experiencing the following problem.

While editing in batch mode within SfGrid, I use the AutoFill feature.

If I perform an operation on a single DropDownList, I don’t encounter any issues.

However, if I use the AutoFill feature by copying values across multiple DropDownLists, only the value of the first DropDownList works correctly, while the values of the other DropDownLists do not function properly during the saving process.

When I debug during the BeforeAutoFill stage, I can see that the value assignments are made correctly, but during the save process, the value fields come as null.

In the code below, the values of InspectorRequesterId and ReportingPersonId are null in the BatchSaveHandler.

However, if I process the columns one by one, I do not face any issues.

For example, if I copy values in the Company column and save it (if I don’t save and move to another column, the issue occurs again) and then perform the same operation on another column, I don’t experience any problems. When selecting multiple columns, the first column works fine.

I also tried converting DropDownLists into ComboBox, but the same issue persists.

I would really appreciate any help in resolving this issue.


<SfGrid @ref="gridConstructionDept" RowHeight="28" EnableInfiniteScrolling="true" DataSource="@entity" AllowSorting="true"

                AllowFiltering="true" Height="100%" Width="auto" ShowColumnChooser="true" EnableStickyHeader="true"

                AllowTextWrap="false" AllowGrouping="false" AllowReordering="true" AllowResizing="true"

                EnableAltRow="true" EnableHover="true" AllowExcelExport="true" EnableAutoFill="true" AllowSelection="true"

                Toolbar="@Toolbaritems"

                ContextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll" })">

            <GridEvents OnBatchSave="BatchSaveHandler"

                        BeforeAutoFillCell="BeforeAutoFillCell" TValue="ConstructionDeptList">

            </GridEvents>

            <GridSelectionSettings AllowDragSelection="true"

                                   CellSelectionMode="CellSelectionMode.Box"

                                   Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell"

                                   Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>

            <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"

                              ShowConfirmDialog="true"

                              AllowNextRowEdit="true" AllowEditOnDblClick="true"/>


                               <GridColumns>

                <GridColumn Field="@nameof(ConstructionDeptList.Id)" Visible="false" HeaderText="@L["Id"]" AllowAdding="false" AllowEditing="false"

                            IsPrimaryKey="true" Width="60"></GridColumn>


                            <GridColumn Field="@nameof(ConstructionDeptList.CompanyName)" ClipMode="ClipMode.EllipsisWithTooltip" EditType="EditType.DropDownEdit"

                            HeaderText="@L["Company"]" AutoFit="true">

                    <Template>

                        @((context as ConstructionDeptList).CompanyName)

                    </Template>

                    <EditTemplate>

                        @{

                            var companyId = (context as ConstructionDeptList)?.CompanyId ?? 0;

                        }

                        <SfDropDownList ID="CompanyId" AllowFiltering="true" ShowClearButton="true" FilterType="FilterType.Contains" TItem="CompanyList"

                                        PopupWidth="250" @bind-Value="companyId" Placeholder=@L["Company"] TValue="int" DataSource="@companyLists">

                            <DropDownListFieldSettings Value="Id" Text="CompanyName">

                            </DropDownListFieldSettings>

                            <DropDownListEvents TValue="int" TItem="CompanyList"

                                                ValueChange="@(args => OnCompanyChange(context as ConstructionDeptList, args.Value))">

                            </DropDownListEvents>

                        </SfDropDownList>

                    </EditTemplate>

                </GridColumn>

                <GridColumn Field="@nameof(ConstructionDeptList.ConstructionDepStartDate)"

                            Type="ColumnType.DateTime" Format="dd.MM.yyyy" HeaderText="@L["StartDate"]" AutoFit="true"></GridColumn>

                <GridColumn Field="@nameof(ConstructionDeptList.ConstructionDeptEndDate)"

                            Type="ColumnType.DateTime" Format="dd.MM.yyyy" HeaderText="@L["EndDate"]" AutoFit="true"></GridColumn>

                <GridColumn Field="@nameof(ConstructionDeptList.ActualQuantity)" EditType="EditType.NumericEdit" Format="N2" HeaderText="@L["ActualQuantity"]"

                            AutoFit="true"></GridColumn>

                <GridColumn Field="@nameof(ConstructionDeptList.ReportingPersonName)" HeaderText="@L["ReportingPerson"]" EditType="EditType.DropDownEdit"

                            AutoFit="true">

                    <Template>

                        @((context as ConstructionDeptList).ReportingPersonName)

                    </Template>

                    <EditTemplate>

                        @{

                            var reportingPersonId = (context as ConstructionDeptList)?.ReportingPersonId ?? 0;

                        }

                        <SfDropDownList ID="ReportingPersonId" AllowFiltering="true" ShowClearButton="true" FilterType="FilterType.Contains" TItem="PersonList"

                                        PopupWidth="250"

                                        @bind-Value="reportingPersonId"

                                        Placeholder=@L["ReportingPerson"] TValue="int" DataSource="@personLists">

                            <DropDownListFieldSettings Value="Id" Text="PersonName"></DropDownListFieldSettings>

                            <DropDownListEvents TValue="int" TItem="PersonList"

                                                ValueChange="@(args => OnReportingPersonChange(context as ConstructionDeptList, args.Value))">

                            </DropDownListEvents>

                        </SfDropDownList>

                    </EditTemplate>

                </GridColumn>


                <GridColumn Field="@nameof(ConstructionDeptList.InspectorRequesterName)" HeaderText="@L["InspectorRequester"]" EditType="EditType.DropDownEdit"

                            AutoFit="true">

                    <Template>

                        @((context as ConstructionDeptList).InspectorRequesterName)

                    </Template>

                    <EditTemplate>

                        @{

                            var inspectorRequesterId = (context as ConstructionDeptList)?.InspectorRequesterId ?? 0;

                        }

                        <SfDropDownList ID="InspectorRequesterId" AllowFiltering="true" ShowClearButton="true" FilterType="FilterType.Contains"

                                        TItem="PersonList" PopupWidth="250"

                                        @bind-Value="inspectorRequesterId"

                                        Placeholder=@L["InspectorRequester"] TValue="int" DataSource="@personLists">

                            <DropDownListFieldSettings Value="Id" Text="PersonName"></DropDownListFieldSettings>

                            <DropDownListEvents TValue="int" TItem="PersonList"

                                                ValueChange="@(args => OnInspectorRequesterChange(context as ConstructionDeptList, args.Value))">

                            </DropDownListEvents>

                        </SfDropDownList>

                    </EditTemplate>

                </GridColumn>

                </GridColumns>

        </SfGrid>


        public async Task BatchSaveHandler(BeforeBatchSaveArgs<ConstructionDeptList> args)

    {

     var added = args.BatchChanges.AddedRecords;

        var updated = args.BatchChanges.ChangedRecords;

        var deleted = args.BatchChanges.DeletedRecords;

         var validRecords = updated.ToList();

         if (validRecords.Any() || added.Any())

            {

                args.BatchChanges.ChangedRecords = validRecords;

                operationResult = await ConstructionDeptRepository.UpdateBatch(added, validRecords, []);

                await ShowResultMessageAsync(operationResult, () => Task.CompletedTask);

            }

            }

            private async Task BeforeAutoFillCell(BeforeAutoFillCellEventArgs<ConstructionDeptList> args)

    {

        try

        {

            switch (args.ColumnName)

            {

                case nameof(ConstructionDeptList.ReportingPersonName):

                    await UpdatePersonInfoAsync(args, nameof(ConstructionDeptList.ReportingPersonId), nameof(ConstructionDeptList.ReportingPersonName));

                    break;

                case nameof(ConstructionDeptList.InspectorRequesterName):

                    await UpdatePersonInfoAsync(args, nameof(ConstructionDeptList.InspectorRequesterId), nameof(ConstructionDeptList.InspectorRequesterName));

                    break;

                case nameof(ConstructionDeptList.CompanyName):

                    await UpdateCompanyInfoAsync(args);

                    break;

            }

        }

        catch (Exception ex)

        {

            Console.WriteLine($"Error in BeforeAutoFillCell: {ex.Message}");

        }

    }

     private async Task UpdatePersonInfoAsync(BeforeAutoFillCellEventArgs<ConstructionDeptList> args, string idField, string nameField)

    {

        var selectedPerson = personLists.FirstOrDefault(a => a.PersonName == (string)args.Value);

        if (selectedPerson != null)

        {

            args.Data.GetType().GetProperty(idField)?.SetValue(args.Data, selectedPerson.Id);

            args.Data.GetType().GetProperty(nameField)?.SetValue(args.Data, selectedPerson.PersonName);

            await gridConstructionDept.UpdateCellAsync(args.RowIndex, idField, selectedPerson.Id);

            await gridConstructionDept.UpdateCellAsync(args.RowIndex, nameField, selectedPerson.PersonName);

        }

    }


    private async Task UpdateCompanyInfoAsync(BeforeAutoFillCellEventArgs<ConstructionDeptList> args)

    {

        var selectedCompany = companyLists.FirstOrDefault(a => a.CompanyName == (string)args.Value);

        if (selectedCompany != null)

        {

            args.Data.CompanyId = selectedCompany.Id;

            args.Data.CompanyName = selectedCompany.CompanyName;

            await gridConstructionDept.UpdateCellAsync(args.RowIndex, nameof(ConstructionDeptList.CompanyId), selectedCompany.Id);

            await gridConstructionDept.UpdateCellAsync(args.RowIndex, nameof(ConstructionDeptList.CompanyName), selectedCompany.CompanyName);

        }

    }


1 Reply

SK Sanjay Kumar Suresh Syncfusion Team February 18, 2025 03:22 PM UTC

Hi Ali Y,


While checking your query we can see that the autofill feature is not working properly on your scenario, To investigate further, we created a simple sample using the provided code snippet and tested it from our end. However, we were unable to reproduce the issue. We have attached the sample ensured from our end please check from your end and let us know whether any modifications required to reproduce the issue you are facing.


Sample Ensured from our End:

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


Before proceeding with the reported requirement, we require some additional clarification from your end. Please share the below details to proceed further at our end.


  1. Please provide a simple issue replicating sample or try to modify the attached sample.
  2. Share us the video demonstration of the reported behavior.
  3. Please share the step by step replication procedure to reproduce the issue.
  4. Please provide the information whether you are issue scenario is performing autofill across the columns scenario or same column scenario.


The above requested detail will be very helpful for us to validate the reported issue at our end.


Regards,

Sanjay Kumar Suresh


Attachment: screencapture_(4)_54782a4.7z

Loader.
Up arrow icon