Refresh Dropdown with Custom DataAdapter

Hi 


I have a cascading dropdown scenario. The second dropdown uses a Custom Data adapter. I would like to use the first dropdown to set a parameter of the CustomAdapter and the trigger it to readAsync and then update the Second Dropdown. 


I am using ServerSide Blazor. My custom adapter is a scoped instance injected into the page.


I have searched here but not found anything relevant to current version at time of posting.


4 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team January 5, 2022 02:50 PM UTC

Hi Reibelt, 

We have validated your requirement. We need two more business days to prepare the sample from our end. We will update the further details in two business days (January 7th, 2022).  

Regards, 
Sureshkumar P 



SP Sureshkumar P Syncfusion Team January 12, 2022 01:25 PM UTC

Hi Reibelt, 
 
Based on the details provided, we have prepared the cascading sample by using the DropDownList component with help of custom adaptor. Please find the code snippet and sample below. 
@using Syncfusion.Blazor.DropDowns 
@using Syncfusion.Blazor.Data 
@using Syncfusion.Blazor 
<div class="col-lg-12 control-section"> 
    <div class="control-wrapper"> 
        <div class="padding-top"> 
            <SfDropDownList TValue="int?" 
                            TItem="Countries" 
                            Placeholder="Select a value" 
                            Query="@fieldQuery" 
                            AllowFiltering="true"> 
                <SfDataManager AdaptorInstance="@typeof(CountryCustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
                <DropDownListEvents TItem="Countries" TValue="int?" ValueChange="ChangeCountry"></DropDownListEvents> 
                <DropDownListFieldSettings Value="CountryId" Text="CountryName"></DropDownListFieldSettings> 
            </SfDropDownList> 
        </div> 
        <div class="padding-top"> 
            <SfDropDownList Enabled="@EnableStateDropDown" @bind-Value="@StateValue" 
                            TValue="int?" 
                            TItem="State" 
                            Placeholder="Select a value" 
                            Query="@StateQuery" 
                            AllowFiltering="true"> 
                <SfDataManager AdaptorInstance="@typeof(StateCustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
                <DropDownListFieldSettings Value="StateId" Text="StateName"></DropDownListFieldSettings> 
            </SfDropDownList> 
        </div> 
    </div> 
</div> 
<style> 
    .control-wrapper { 
        margin0 auto; 
        width250px; 
    } 
    .control-section .padding-top { 
        padding-top35px 
    } 
</style> 
@code{ 
    public bool EnableStateDropDown = false; 
    public int? StateValue { get; set; } = null; 
     public Query StateQuery { get; set; } = null; 
    public Query fieldQuery = new Query(); 
    public int ValueList = new int { }; 
    public void ChangeCountry(Syncfusion.Blazor.DropDowns.ChangeEventArgs<int?, Countries> args) 
    { 
        this.EnableStateDropDown = true; 
        this.StateQuery = new Query().Where(new WhereFilter() { Field = "CountryId", Operator = "equal", value = args.Value, IgnoreCase = false, IgnoreAccent = false }); 
        this.StateValue = null; 
    } 
} 
namespace AutocompleteV18_1_46.Pages 
{ 
    public class State 
    { 
        public State() { } 
        public State(int StateId, string StateName) 
        { 
            this.StateId = StateId; 
            this.StateName = StateName; 
        } 
        public string StateName { getset; } 
        public int CountryId { getset; } 
        public int StateId { getset; } 
        private static List<State> GetData() 
        { 
            List<State> States = new List<State>() { 
        new State() { StateName= "New York", CountryId= 1, StateId= 101 }, 
        new State() { StateName= "Queensland", CountryId= 2, StateId= 104 }, 
        new State() { StateName= "Tasmania ", CountryId= 2, StateId= 105 }, 
        new State() { StateName= "Victoria", CountryId= 2, StateId= 106 }, 
        new State() { StateName= "Virginia", CountryId= 1, StateId= 102 }, 
        new State() { StateName= "Washington", CountryId= 1, StateId= 103 } 
    }; 
            return States; 
        } 
        public static async Task<List<State>> GetAllRecords() 
        { 
            return await Task.Run(() => GetData()); 
        } 
    } 
    public class StateCustomAdaptor : DataAdaptor 
    { 
        public static List<State> States = new List<State>() { 
        new State() { StateName= "New York", CountryId= 1, StateId= 101 }, 
        new State() { StateName= "Queensland", CountryId= 2, StateId= 104 }, 
        new State() { StateName= "Tasmania ", CountryId= 2, StateId= 105 }, 
        new State() { StateName= "Victoria", CountryId= 2, StateId= 106 }, 
        new State() { StateName= "Virginia", CountryId= 1, StateId= 102 }, 
        new State() { StateName= "Washington", CountryId= 1, StateId= 103 } 
    }; 
        public override async Task<cke:object> ReadAsync(DataManagerRequest dm, string key = null) 
        { 
            IEnumerable<State> DataSource = await State.GetAllRecords(); 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                DataSource = DataOperations.PerformSearching(DataSource, dm.Search);  //Search 
            } 
            if (dm.Sorted != null && dm.Sorted.Count > 0//Sorting 
            { 
                DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted); 
            } 
            if (dm.Where != null && dm.Where.Count > 0//Filtering 
            { 
                DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
            } 
            int count = DataSource.Cast<State>().Count(); 
            if (dm.Skip != 0) 
            { 
                DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);         //Paging 
            } 
            if (dm.Take != 0) 
            { 
                DataSource = DataOperations.PerformTake(DataSource, dm.Take); 
            } 
            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; 
        } 
    } 
} 
 
 
 
Regards, 
Sureshkumar P 


Marked as answer

DR Daniel Reibelt January 12, 2022 09:32 PM UTC

Thanks, I think it was unclear that the Query could be used this way when using a custom adapter, but makes sense.


This solves my issue.







SP Sureshkumar P Syncfusion Team January 13, 2022 10:03 AM UTC

Hi Reibelt, 
 
Thanks for your update. 
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon