SfDropDownList Value is null when DataSource is Empty

i need help please,

when enter to EditForm in edit with Value (example : 87912e32-b1a2-49d3-85d8-c72a4d6daef7 ) in SfDropDownList and DataSource is empty .. the Value set to null 

the following code is show :

<SfDropDownList TValue="Guid?" TItem="EmployeeDropDownListViewModel" @bind-Value="ViewModel.EmployeeRowId"

                            ShowClearButton="true" DataSource="employees"

                            AllowFiltering="true" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains"

                            Placeholder="@_sharedLocalizer["Choose"]" 

                <DropDownListFieldSettings Value="RowId" Text="Name"></DropDownListFieldSettings>

            </SfDropDownList>

@code {

    private List<EmployeeDropDownListViewModel> employees;

    protected override async Task OnAfterRenderAsync(bool firstRender)

    {

        if (firstRender)

        {

            try

            {

                 // here ViewModel.EmployeeRowId is  87912e32-b1a2-49d3-85d8-c72a4d6daef7 

                employees = await HttpService.GetAsync<List<EmployeeDropDownListViewModel>>                               ($"/api/EmployeeDropDownListViewModels/GetEmployeesForDropDownList");

                 // here ViewModel.EmployeeRowId become null and validation is fire 

                await base.OnAfterRenderAsync(firstRender);

            }

            catch (Exception exception)

            {

                Log.Error(exception, Utilities.GetExceptionErrorString(exception));

                _toaster.ShowToaster(exception.Message, ToasterType.Error);

            }

        }

    }

}

image_36.png



6 Replies

MF Mohammad Fayed July 2, 2021 01:16 AM UTC

here some code that show what i mean 


Attachment: PermissionTest_6f2dc026.rar


BC Berly Christopher Syncfusion Team July 4, 2021 04:19 PM UTC

Hi Mohammad, 

Greetings from Syncfusion support. 

We will check and update the details in two business days (6th July 2021). We appreciate your patience until then. 

Regards, 
Berly B.C 



DR Deepak Ramakrishnan Syncfusion Team July 6, 2021 04:18 PM UTC

Hi Mohammad,  
  
Sorry for the inconvenience caused.  

We are facing complexity in our end, so we need additional time to validate this query. We update further details in 2 business days (July 8, 2021). We appreciate your patience until then.  

Regards, 
Deepak Ramakrishnan. 



BC Berly Christopher Syncfusion Team July 8, 2021 02:55 PM UTC

Hi Mohammad, 
  
Thanks for the patience. 
  
By default, the entered value will be filtered based on “text” field in the DropDownList component. To filter items in DropDownList component based on value field, use Query of DataManager using the Filtering event. The filtered data can be again updated using the UpdateData method. Kindly refer the below code example. 
  
<EditForm Model="ChemOrderTable"> 
    <SfDropDownList @ref="DropObj" TValue="Guid?" TItem="EmployeeDropDownListViewModel" 
                    ShowClearButton="true" DataSource="employees" 
                    AllowFiltering="true" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains" 
                    Placeholder="Choose"> 
 
                <DropDownListFieldSettings Value="RowId" Text="Name"></DropDownListFieldSettings> 
        <DropDownListEvents TValue="Guid?" TItem="EmployeeDropDownListViewModel" Filtering="OnFiltering"></DropDownListEvents> 
            </SfDropDownList> 
</EditForm> 
    @code { 
         
        public async Task OnFiltering(FilteringEventArgs e) 
        { 
            e.PreventDefaultAction = true; 
            query = new Query().Where(new WhereFilter() 
            { 
                Field = "RowId", 
                value = e.Text, 
                Operator = "startswith", 
                IgnoreCase = true 
            }); 
 
            await this.DropObj.Filter(employees, query); 
        } 
    } 
 
  
  
Regards, 
Berly B.C 



MF Mohammad Fayed July 15, 2021 01:32 PM UTC

I'm Sorry, i told you the value binding will be null if DataSource is list empty (example, if i load datasource in OnAfterRenderAsync ).. and this not my order



SN Sevvandhi Nagulan Syncfusion Team July 16, 2021 03:09 PM UTC

Hi Mohammad, 


We checked your query. The value becomes null when the data source is empty. So we request that you to set the value after the data has been loaded.  Kindly refer the following code. 


@code { 
 
    private List<EmployeeDropDownListViewModel> employees; 
 
    protected override async Task OnAfterRenderAsync(bool firstRender) 
 
    { 
 
        if (firstRender) 
 
        { 
 
            try 
 
            { 
 
                 // here ViewModel.EmployeeRowId is  87912e32-b1a2-49d3-85d8-c72a4d6daef7  
 
                employees = await HttpService.GetAsync<List<EmployeeDropDownListViewModel>>($"/api/EmployeeDropDownListViewModels/GetEmployeesForDropDownList"); 
 
                 // here ViewModel.EmployeeRowId become null and validation is fire  
                ViewModel.EmployeeRowId = "87912e32-b1a2-49d3-85d8-c72a4d6daef7"; 
                await base.OnAfterRenderAsync(firstRender); 
 
            } 
 
            catch (Exception exception) 
 
            { 
 
                Log.Error(exception, Utilities.GetExceptionErrorString(exception)); 
 
                _toaster.ShowToaster(exception.Message, ToasterType.Error); 
 
            } 
 
        } 
 
    } 
 
} 



Kindly get back to us for further assistance. 


Regards, 
Sevvandhi N 


Loader.
Up arrow icon