Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions blazor/autocomplete/code-snippet/data-binding/custom-adaptor.razor
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@

@using Syncfusion.Blazor
@using Syncfusion.Blazor.Data
@using Syncfusion.Blazor.DropDowns
<SfAutoComplete TValue="string" Query="RemoteDataQuery" TItem="OrdersDetails" >
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor" ></SfDataManager>
<AutoCompleteFieldSettings Value="OrderID"></AutoCompleteFieldSettings>
@using Syncfusion.Blazor.Data

<SfAutoComplete TValue="string" TItem="Orders">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<AutoCompleteFieldSettings Value="CustomerID"></AutoCompleteFieldSettings>
</SfAutoComplete>

@code{

public Query RemoteDataQuery = new Query().Take(50).RequiresCount();

public class OrdersDetails
public class Orders
{
public Orders() { }
public Orders(int OrderID, string CustomerID)
{
this.OrderID = OrderID;
this.CustomerID = CustomerID;
}
public int OrderID { get; set; }
public string CustomerID { get; set; }
// Example static method to get all records
public static List<OrdersDetails> GetAllRecords()

// Provide a simple in-memory data source for the sample
public static List<Orders> GetAllRecords()
{
var records = new List<OrdersDetails>();
for (int i = 1; i <= 250; i++)
return new List<Orders>
{
records.Add(new OrdersDetails
{
OrderID = i,
CustomerID = $"Customer {i}"
});
}
return records;
new Orders(10248, "VINET"),
new Orders(10249, "TOMSP"),
new Orders(10250, "HANAR"),
new Orders(10251, "VICTE"),
new Orders(10252, "SUPRD")
};
}
}
public class CustomAdaptor : DataAdaptor
{
static readonly HttpClient client = new HttpClient();
public static List<OrdersDetails> order = OrdersDetails.GetAllRecords();
public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null)
public static List<Orders> order = Orders.GetAllRecords();
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable<OrdersDetails> DataSource = order;
IEnumerable<Orders> DataSource = order;
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = DataOperations.PerformSearching(DataSource, dm.Search); //Search
Expand All @@ -49,7 +51,7 @@
{
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<OrdersDetails>().Count();
int count = DataSource.Cast<Orders>().Count();
if (dm.Skip != 0)
{
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); //Paging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Syncfusion.Blazor.Data
@using Syncfusion.Blazor.DropDowns

<SfAutoComplete TValue="string" @ref="autoObj" TItem="Country" Placeholder="e.g. Australia" AllowFiltering="true">
<AutoCompleteFieldSettings Text="Name" Value="Code"></AutoCompleteFieldSettings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

@using Syncfusion.Blazor.DropDowns

<SfAutoComplete TItem="GameFields" TValue="string" DataSource="@Games">
<AutoCompleteEvents TItem="GameFields" TValue="string" Closed="@CloseHandler"></AutoCompleteEvents>
<AutoCompleteFieldSettings Value="Text"></AutoCompleteFieldSettings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
@using Syncfusion.Blazor.Popups;
@using Syncfusion.Blazor.DropDowns;

<SfTooltip @ref="TooltipObj" ID="Tooltip" Target=".e-list-item .name[title]">
</SfTooltip>

<SfAutoComplete TItem="GameFields" TValue="string" Placeholder="Select a game" DataSource="@Games">
<AutoCompleteFieldSettings Text="Text" Value="ID"></AutoCompleteFieldSettings>
<AutoCompleteTemplates TItem="GameFields">
<ItemTemplate>
<div class="name" title="@((context as GameFields).Text)"> @((context as GameFields).Text) </div>
<SfTooltip Target=".custom-item" Content="@context.Text">
<div class="custom-item">@context.Text</div>
</SfTooltip>
</ItemTemplate>
</AutoCompleteTemplates>
<AutoCompleteEvents TValue="string" TItem="GameFields" Opened="OnOpen" OnClose="OnClose"></AutoCompleteEvents>
</SfAutoComplete>

@code {

SfTooltip TooltipObj;
public Boolean isOpen { get; set; } = false;

public class GameFields
Expand All @@ -37,22 +33,4 @@
new GameFields(){ ID= "Game9", Text= "Snooker" },
new GameFields(){ ID= "Game10", Text= "Tennis"},
};

public void OnOpen(PopupEventArgs args)
{
isOpen = true;
}

public void OnClose(PopupEventArgs args)
{
TooltipObj.CloseAsync();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (isOpen)
{
await TooltipObj.RefreshAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@using Syncfusion.Blazor.DropDowns

<p>Selected Value is: @SelectedValue.Name</p>
<p>Selected Value is: @SelectedValue?.Name</p>

<SfAutoComplete TValue="Games" TItem="Games" Width="300px" Placeholder="Select a game" DataSource="@LocalData" @bind-Value="@SelectedValue">
<AutoCompleteFieldSettings Value="Name"/>
Expand Down
4 changes: 4 additions & 0 deletions blazor/autocomplete/native-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Bind any native event by adding the corresponding `@on{event}` attribute to the
In the following example, the `KeyPressed` method is called each time a key is pressed in the input.

```cshtml
@using Syncfusion.Blazor.DropDowns

<SfAutoComplete TValue="string" TItem="Country" @onkeypress="@KeyPressed" DataSource="@LocalData">
<AutoCompleteFieldSettings Value="Name"></AutoCompleteFieldSettings>
</SfAutoComplete>
Expand Down Expand Up @@ -68,6 +70,8 @@ Blazor provides strongly typed event argument classes that map to native events.
In the following example, the keypress handler receives `KeyboardEventArgs`. The message is printed only when the “a” key is pressed.

```cshtml
@using Syncfusion.Blazor.DropDowns

<SfAutoComplete TValue="string" TItem="Country" @onkeypress="@(e => KeyPressed(e))" DataSource="@LocalData">
<AutoCompleteFieldSettings Value="Name"></AutoCompleteFieldSettings>
</SfAutoComplete>
Expand Down
83 changes: 60 additions & 23 deletions blazor/combobox/code-snippet/data-binding/custom-adaptor.razor
Original file line number Diff line number Diff line change
@@ -1,63 +1,100 @@
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Data
@using Syncfusion.Blazor.DropDowns
<SfComboBox TValue="string" Query="RemoteDataQuery" TItem="OrdersDetails" >
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor" ></SfDataManager>
<ComboBoxFieldSettings Value="OrderID" Text="CustomerID"></ComboBoxFieldSettings>
</SfComboBox>

@code{
<SfComboBox TValue="string" TItem="OrdersDetails" Placeholder="Select customer">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<ComboBoxFieldSettings Value="CustomerID" Text="CustomerID"></ComboBoxFieldSettings>
</SfComboBox>

public Query RemoteDataQuery = new Query().Select(new List<string> { "OrderID" }).Take(50).RequiresCount();
@code {
public class Orders
{
public Orders() { }
public Orders(int OrderID, string CustomerID)
{
this.OrderID = OrderID;
this.CustomerID = CustomerID;
}
public int OrderID { get; set; }
public string CustomerID { get; set; }
}

public class OrdersDetails
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
// Example static method to get all records
public string? CustomerID { get; set; }
public int? EmployeeID { get; set; }
public string? ShipCountry { get; set; }

public static List<OrdersDetails> GetAllRecords()
{
var records = new List<OrdersDetails>();
for (int i = 1; i <= 250; i++)
List<OrdersDetails> order = new List<OrdersDetails>();
order.Add(new OrdersDetails() { OrderID = 10248, CustomerID = "VINET", EmployeeID = 5, ShipCountry = "France" });
order.Add(new OrdersDetails() { OrderID = 10249, CustomerID = "TOMSP", EmployeeID = 6, ShipCountry = "Germany" });
order.Add(new OrdersDetails() { OrderID = 10250, CustomerID = "HANAR", EmployeeID = 4, ShipCountry = "Brazil" });
order.Add(new OrdersDetails() { OrderID = 10251, CustomerID = "VICTE", EmployeeID = 3, ShipCountry = "Brazil" });
order.Add(new OrdersDetails() { OrderID = 10252, CustomerID = "SUPRD", EmployeeID = 4, ShipCountry = "Belgium" });
order.Add(new OrdersDetails() { OrderID = 10253, CustomerID = "HANAR", EmployeeID = 3, ShipCountry = "Brazil" });
order.Add(new OrdersDetails() { OrderID = 10254, CustomerID = "CHOPS", EmployeeID = 5, ShipCountry = "Switzerland" });
order.Add(new OrdersDetails() { OrderID = 10255, CustomerID = "RICSU", EmployeeID = 9, ShipCountry = "Switzerland" });
order.Add(new OrdersDetails() { OrderID = 10256, CustomerID = "WELLI", EmployeeID = 3, ShipCountry = "Austria" });
order.Add(new OrdersDetails() { OrderID = 10257, CustomerID = "HILAA", EmployeeID = 4, ShipCountry = "USA" });

for (int i = 1; i <= 40; i++)
{
records.Add(new OrdersDetails
order.Add(new OrdersDetails()
{
OrderID = i,
CustomerID = $"Customer {i}"
OrderID = 10300 + i,
CustomerID = $"CUST{i:D3}",
EmployeeID = (i % 9) + 1,
ShipCountry = i % 2 == 0 ? "India" : "USA"
});
}
return records;

return order;
}
}

public class CustomAdaptor : DataAdaptor
{
static readonly HttpClient client = new HttpClient();

public static List<OrdersDetails> order = OrdersDetails.GetAllRecords();
public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null)

public override object Read(DataManagerRequest dm, string? key = null)
{
IEnumerable<OrdersDetails> DataSource = order;

if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = DataOperations.PerformSearching(DataSource, dm.Search); //Search
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting

if (dm.Sorted != null && dm.Sorted.Count > 0)
{
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering

if (dm.Where != null && dm.Where.Count > 0)
{
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<OrdersDetails>().Count();

int count = DataSource.Count();

if (dm.Skip != 0)
{
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); //Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}

if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}

return dm.RequiresCounts
? new DataResult { Result = DataSource, Count = count }
: (object)DataSource;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Syncfusion.Blazor.Data
@using Syncfusion.Blazor.DropDowns

<SfComboBox TValue="string" @ref="comboObj" TItem="Country" Placeholder="e.g. Australia" DataSource="@Countries" AllowFiltering="true">
<ComboBoxFieldSettings Text="Name" Value="Code"></ComboBoxFieldSettings>
Expand Down
26 changes: 26 additions & 0 deletions blazor/combobox/code-snippet/popup-setting/opened-event.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@using Syncfusion.Blazor.DropDowns

<SfComboBox TItem="GameFields" TValue="string" DataSource="@Games">
<ComboBoxEvents TItem="GameFields" TValue="string" Opened="@OnOpenHandler"></ComboBoxEvents>
<ComboBoxFieldSettings Text="Text" Value="ID"></ComboBoxFieldSettings>
</SfComboBox>

@code {
public class GameFields
{
public string ID { get; set; }
public string Text { get; set; }
}

private List<GameFields> Games = new List<GameFields>() {
new GameFields(){ ID= "Game1", Text= "American Football" },
new GameFields(){ ID= "Game2", Text= "Badminton" },
new GameFields(){ ID= "Game3", Text= "Basketball" },
new GameFields(){ ID= "Game4", Text= "Cricket" },
};

private void OnOpenHandler(PopupEventArgs args)
{
// Here, you can customize your code.
}
}
25 changes: 25 additions & 0 deletions blazor/combobox/code-snippet/popup-setting/poupu-zindex.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@using Syncfusion.Blazor.DropDowns

<SfComboBox TValue="string" TItem="Games" ZIndex="2000" Placeholder="Select a game" DataSource="@LocalData">
<ComboBoxFieldSettings Value="ID" Text="Text"></ComboBoxFieldSettings>
</SfComboBox>

@code {
public class Games
{
public string ID { get; set; }
public string Text { get; set; }
}
List<Games> LocalData = new List<Games> {
new Games() { ID= "Game1", Text= "American Football" },
new Games() { ID= "Game2", Text= "Badminton" },
new Games() { ID= "Game3", Text= "Basketball" },
new Games() { ID= "Game4", Text= "Cricket" },
new Games() { ID= "Game5", Text= "Football" },
new Games() { ID= "Game6", Text= "Golf" },
new Games() { ID= "Game7", Text= "Hockey" },
new Games() { ID= "Game8", Text= "Rugby"},
new Games() { ID= "Game9", Text= "Snooker" },
new Games() { ID= "Game10", Text= "Tennis"},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@using Syncfusion.Blazor.DropDowns

<SfComboBox TValue="string" @ref="dropdownObj" TItem="Games" ZIndex="2000" Placeholder="Select a game" DataSource="@LocalData">
<ComboBoxFieldSettings Value="ID" Text="Text"></ComboBoxFieldSettings>
<ComboBoxEvents TItem="Games" TValue="string" Created="@CreatedHandler"></ComboBoxEvents>
</SfComboBox>

@code {

SfComboBox<string , Games> dropdownObj { get; set; }


public class Games
{
public string ID { get; set; }
public string Text { get; set; }
}
List<Games> LocalData = new List<Games> {
new Games() { ID= "Game1", Text= "American Football" },
new Games() { ID= "Game2", Text= "Badminton" },
new Games() { ID= "Game3", Text= "Basketball" },
new Games() { ID= "Game4", Text= "Cricket" },
new Games() { ID= "Game5", Text= "Football" },
new Games() { ID= "Game6", Text= "Golf" },
new Games() { ID= "Game7", Text= "Hockey" },
new Games() { ID= "Game8", Text= "Rugby"},
new Games() { ID= "Game9", Text= "Snooker" },
new Games() { ID= "Game10", Text= "Tennis"},
};

private async Task CreatedHandler(Object args)
{
await dropdownObj.ShowPopupAsync();
}
}
Loading