|
@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 {
margin: 0 auto;
width: 250px;
}
.control-section .padding-top {
padding-top: 35px
}
</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 { get; set; }
public int CountryId { get; set; }
public int StateId { get; set; }
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<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;
}
}
} |