Update one control based on value from another when in EditMode.Dialog

I'm trying to do something that I thought would be simple but I'm having issues.  I'm converting an existing EditMode.Batch grid to use EditMode.Dialog instead.  I previously had code that ran in the CellSaved event to update the data in a date column for the selected row.  This was my previous code:

    public async Task CellSavedHandler(CellSavedArgs<ProductLicensorMilestone> args)

    {

        if (args.ColumnName == "StatusId" && args.RowData.StatusDate == null)

        {

            var index = Grid!.SelectedRowIndex;


            if (args.Data.StatusId.HasValue)

                await Grid!.UpdateCellAsync(index, "StatusDate", DateTime.Now);

        }

    }

How do I perform the same action when I'm in an Dialog modal?


5 Replies

PS Prathap Senthil Syncfusion Team October 8, 2024 12:30 PM UTC

Hi Seth,

Based on your query, we would like to clarify that the CellSaved event and the UpdateCellAsync method are only supported for batch editing. Therefore, if you are using batch mode instead of the dialog, we recommend referring to the attached documentation. We have already discussed your scenario and documented this topic. Kindly refer to the documentation below for your reference."


Reference:
https://blazor.syncfusion.com/documentation/datagrid/dialog-editing#implement-calculated-column-inside-grid-dialog-editing

Regards,
Prathap Senthil



SE Seth October 8, 2024 12:43 PM UTC

I understand.  If you read my original question again, I mention that I'm moving FROM batch editing to Dialog editing.  I need to know how to handle the ValueChange event of a SfDropdown and set the value of an SfDatePicker to the current date.  That's what the above-mentioned "batch" code was doing but I don't know how to do it while in an Edit dialog.




PS Prathap Senthil Syncfusion Team October 9, 2024 09:49 AM UTC

Based on your requirement, we have created a simple sample. Kindly refer to the code snippet and sample below for your reference.

<SfGrid @ref="GridRef" AllowPaging="true" DataSource="@GridData" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">

    <GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@Syncfusion.Blazor.Grids.EditMode.Dialog"></GridEditSettings>

    <GridColumns>

        -----------

        <GridColumn Field=@nameof(Orders.ShipCountry) HeaderText="Ship Country" EditType="Syncfusion.Blazor.Grids.EditType.DropDownEdit" Width="150">

            <EditTemplate>

                @{

                    var data = context as Orders;

                    <SfDropDownList ID="ShipCountry" Placeholder="Select a Country" TItem="string" TValue="string" @bind-Value="@(data.ShipCountry)" DataSource="@Countries">

                        <DropDownListEvents TValue="string" TItem="string" ValueChange=@(async (args) => await ValueChange(args, data))></DropDownListEvents>

                        <DropDownListFieldSettings Text="ShipCountry" Value="ShipCountry"></DropDownListFieldSettings>

                    </SfDropDownList>

                }

 

            </EditTemplate>

        </GridColumn>

        <GridColumn Field=@nameof(Orders.OrderDate) HeaderText="Order Date" Format="d" Type="Syncfusion.Blazor.Grids.ColumnType.Date" Width="160">

            <EditTemplate>

                @{

                    var data = context as Orders;

                    <SfDatePicker ID="OrderDate" @bind-Value="@(data.OrderDate)" Format="d"></SfDatePicker>

 

                }

            </EditTemplate>

        </GridColumn>

      

    </GridColumns>

</SfGrid>

 

@code {

    SfGrid<Orders> GridRef;

    public List<Orders> GridData { get; set; } = new List<Orders>();

    public async Task ValueChange(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, string> args , Orders orders)

    {

 

        // here you can customize based on your need,

        if (args.Value == "United States")

        {

            orders.OrderDate = DateTime.Now;

        }

        else if (args.Value == "Australia")

        {

            orders.OrderDate = DateTime.Now;

        }

        GridRef.PreventRender(false);

    }

 

  

}


Reference: Class SfGrid<TValue> - Blazor API Reference | Syncfusion


Attachment: BlazorServerApp_(4)_157f1b9b.zip


SE Seth October 9, 2024 10:50 AM UTC

Thank you, this is exactly what I was looking for.



PS Prathap Senthil Syncfusion Team October 10, 2024 06:32 AM UTC

Thanks for the update,


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


Please get back to us if you have further queries.


Loader.
Up arrow icon