Refreshing fields inside grideditsetting template

I'm using grideditsetting and a template inside a grid to show the row details and modify the fields.

Supposing I use inside this template some dropdownlist with data bound to another table and supposing a use a button inside the grideditsetting template where if I click on it I add a row in the table of the dropdownlist, how can I refresh the dropdownlist to show also the new data inserted ?

I tried to load again the datasource of the dropdownlist and to call the refreshdatasync() but the data are not refreshed. Only if I close the grid row details and I open it again I can see the new record in the dropdownlist


<SfGrid @ref="Gridpro" DataSource="@ListaProposte" >

GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog" ShowDeleteConfirmDialog="true" >

 <Template>

            @{

                var pro = (context as PropostaDTO);

            }

                       <label class="e-float-text e-label-top">Cliente</label>

                        <SfDropDownList @ref="clienteref" Width="300px" TValue="int" TItem="ClientiGivDTO" @bind-Value="@(pro.IdCliente)" DataSource="@clienti" PopupWidth="250px">

                            <DropDownListFieldSettings Value="idcliente" Text="nome"></DropDownListFieldSettings>

                        </SfDropDownList>

                        <SfButton CssClass="sf-icons" IconCss="sf-icons sf-icon-edit-01-wf" @onclick="@(e => Mostraelenco())"></SfButton>

</Template>

....


protected override async Task OnInitializedAsync()

    {

        ListaProposte = ProposteService.GetProposteDTO(filiale,anno).ToList();

        clienti = ClienteService.GetclientiDTO(_filiale).ToList();

    }

private void AggiornaStatoCli(ClientiGiv args)

    {

        mostraelencocli = false;

            clienti = ClienteService.GetclientiDTO(_filiale).ToList();

           clienteref.RefreshDataAsync();

        }


    }

Mostraelenco() shows a dialog where I add a record inside clienti and then I call  AggiornaStatoCli but the dropdownlist doesn't show the new record inside the list


2 Replies

SP Sarveswaran Palani Syncfusion Team September 18, 2023 01:18 PM UTC

Hi Walter,


Greetings from Syncfusion support.


We would like to inform you that we have prevented unwanted rendering of Grid component during the external action for better performance, so the value is not updated. We suggest you to use PreventRender(false) on value change event to reflect the changes correctly.


Kindly use the below highlighted changes in the value change event and check the reported issue at your end. If still issue persist, kindly share the runnable sample and grid code snippet to us. Based on that, we’ll validate and provide solution ASAp  from our end.


 

<SfGrid DataSource="@GridSourceList"

        TValue="GridItem"

@ref="Grid"

        AllowPaging="true"

        Toolbar="@(new string[] { "Add", "Edit", "Delete" })">

    <GridEditSettings AllowAdding="true"

                      AllowDeleting="true"

                      AllowEditing="true"

                      Mode="EditMode.Dialog"

                      Dialog="@(new DialogSettings() { AllowDragging = true, Width="80%", EnableResize=true})"

                      AllowEditOnDblClick="true">

        <HeaderTemplate>

            <h4>Editing !</h4>

        </HeaderTemplate>

        <Template>

            @{

                var gridItem = (context as GridItem);

                <div class="container">

                    <div class="row">

                        <div class="col">

                            <SfDropDownList TValue="string"

                                            FloatLabelType="FloatLabelType.Always"

                                            Placeholder="Select one Item"

                                            TItem="DropDownItem"

                            @bind-Value="@gridItem.ItemUno"

                                            DataSource="DropSourceList">

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

                                <DropDownListEvents TValue="string" TItem="DropDownItem" ValueChange="@valueChanged" />

                            </SfDropDownList>

                        </div>

                    </div>

                    @if (!string.IsNullOrEmpty(gridItem.ItemUno))

                    {

                        <div class="row" style="margin-top:20px">

                            <div class="col">

                                <span><strong>Dialog Has Refreshed</strong></span>

                            </div>

                        </div>

                    }

                </div>

            }

        </Template>

    </GridEditSettings>

 

    <GridColumns>

        <GridColumn Field="@nameof(GridItem.Id)" IsPrimaryKey=true Visible="false" />

        <GridColumn Field="@nameof(GridItem.ItemUno)" HeaderText="Address" IsPrimaryKey=true />

    </GridColumns>

</SfGrid>

 

@code

{

    private List<GridItem> GridSourceList { get; set; }

    private List<DropDownItem> DropSourceList { get; set; }

    private SfGrid<GridItem> Grid { get; set; }

    private void valueChanged()

    {

        Grid.PreventRender(false);

    }

   

    

}

 


Please let us know if you have any queries.


Regards,

Sarvesh



WM Walter Martin September 26, 2023 12:19 PM UTC

This works exactly as I needed

Many thanks



Loader.
Up arrow icon