-
Notifications
You must be signed in to change notification settings - Fork 63
Documentation(954494) - Revamp How to topic in blazor platform #5883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gayathri4135
wants to merge
16
commits into
hotfix/hotfix-v29.1.33
Choose a base branch
from
954494-how-to
base: hotfix/hotfix-v29.1.33
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0bfec2a
Documentation(954494) - Revamp How to topic in blazor platform
Gayathri4135 a603a4b
Updated the md file
Gayathri4135 b62f4d7
Update the md file
Gayathri4135 411c427
updated the md file
Gayathri4135 1237244
updated the md file
Gayathri4135 945b8bb
updated the md file
Gayathri4135 85793c6
Updated the md file
Gayathri4135 c187b57
Updated the md file
Gayathri4135 f162097
Updated the sample
Gayathri4135 4c11673
updated the md file
Gayathri4135 d94b75e
Updated the md file
Gayathri4135 d0e71c3
Updated the md file
Gayathri4135 bd377eb
Updated the md file
Gayathri4135 d843200
Updated the md file
Gayathri4135 164828e
updated the md file
Gayathri4135 d373c23
update the md file
Gayathri4135 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
603 changes: 486 additions & 117 deletions
603
blazor/datagrid/how-to/blazor-webassembly-data-grid-using-cli.md
Large diffs are not rendered by default.
Oops, something went wrong.
120 changes: 81 additions & 39 deletions
120
blazor/datagrid/how-to/change-datasource-dynamically.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,110 @@ | ||
--- | ||
layout: post | ||
title: Change datasource dynamically in Syncfusion Blazor DataGrid Component | ||
description: Learn here all about Change datasource dynamically in Syncfusion Blazor DataGrid component and more. | ||
title: Change datasource dynamically in Syncfusion Blazor DataGrid | ||
description: Learn here all about change datasource dynamically in Syncfusion Blazor DataGrid and more. | ||
platform: Blazor | ||
control: DataGrid | ||
documentation: ug | ||
--- | ||
|
||
# Change Datasource Dynamically in Blazor DataGrid Component | ||
# Change Datasource Dynamically in Blazor DataGrid | ||
|
||
You can change the [DataSource](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeries.html#Syncfusion_Blazor_Charts_ChartSeries_DataSource) of the datagrid component dynamically through an external button. | ||
The Syncfusion Blazor DataGrid allows to change the [DataSource](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeries.html#Syncfusion_Blazor_Charts_ChartSeries_DataSource) of the Grid dynamically through an external button. This feature is useful to display different sets of data based on specific actions. | ||
|
||
This is demonstrated in the following sample code where the [DataSource](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeries.html#Syncfusion_Blazor_Charts_ChartSeries_DataSource) is dynamically modified using the bounded property, | ||
To implement this: | ||
|
||
* Bind the Grid's `DataSource` property to a public list (e.g., Orders). | ||
|
||
* Create a method that replaces this list with a new set of data. | ||
|
||
* Trigger this method through a button or any other user interaction. | ||
|
||
* The Grid automatically detects the data change and re-renders with the new content. | ||
|
||
The following example demonstrates how to change the `DataSource` of the Grid dynamically: | ||
|
||
|
||
{% tabs %} | ||
{% highlight razor tabtitle="Index.razor" %} | ||
|
||
```cshtml | ||
@using Syncfusion.Blazor.Grids | ||
@using Syncfusion.Blazor.Buttons | ||
|
||
<SfButton OnClick="Change">Change data source dynamically</SfButton> | ||
<SfButton OnClick="ChangeDataSource">Change Data Source</SfButton> | ||
|
||
<SfGrid DataSource="@Orders" AllowPaging="true"> | ||
<GridPageSettings PageSize="8"></GridPageSettings> | ||
<SfGrid @ref="grid" DataSource="@Orders" AllowPaging="true"> | ||
<GridColumns> | ||
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> | ||
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> | ||
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type=ColumnType.Date TextAlign="TextAlign.Right" Width="130"></GridColumn> | ||
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> | ||
</GridColumns> | ||
<GridColumn Field=@nameof(OrderData.OrderID) HeaderText="Order ID" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right" Width="120"></GridColumn> | ||
<GridColumn Field=@nameof(OrderData.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> | ||
<GridColumn Field=@nameof(OrderData.OrderDate) HeaderText="Order Date" Format="d" Type="Syncfusion.Blazor.Grids.ColumnType.Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right" Width="130"></GridColumn> | ||
<GridColumn Field=@nameof(OrderData.Freight) HeaderText="Freight" Format="C2" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right" Width="120"></GridColumn> | ||
</GridColumns> | ||
</SfGrid> | ||
|
||
@code{ | ||
public List<Order> Orders { get; set; } | ||
@code { | ||
private SfGrid<OrderData> grid; | ||
public List<OrderData> Orders { get; set; } | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Orders = Enumerable.Range(1, 75).Select(x => new Order() | ||
{ | ||
OrderID = 1000 + x, | ||
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], | ||
Freight = 2.1 * x, | ||
OrderDate = DateTime.Now.AddDays(-x), | ||
}).ToList(); | ||
Orders = OrderData.GetAllRecords(); | ||
} | ||
|
||
private void ChangeDataSource() | ||
{ | ||
// Replace the DataSource with a new list of records. | ||
Orders = OrderData.GetNewRecords(); | ||
} | ||
public void Change() | ||
} | ||
|
||
{% endhighlight %} | ||
{% highlight c# tabtitle="OrderData.cs" %} | ||
|
||
public class OrderData | ||
{ | ||
public static List<OrderData> Orders = new List<OrderData>(); | ||
|
||
public OrderData() { } | ||
|
||
public OrderData(int orderID, string customerID, double freight, DateTime? orderDate) | ||
{ | ||
// Data source is modified dynamically | ||
this.Orders = Enumerable.Range(1, 45).Select(x => new Order() | ||
this.OrderID = orderID; | ||
this.CustomerID = customerID; | ||
this.Freight = freight; | ||
this.OrderDate = orderDate; | ||
} | ||
|
||
public static List<OrderData> GetAllRecords() | ||
{ | ||
if (Orders.Count == 0) | ||
{ | ||
OrderID = 100 + x, | ||
CustomerID = (new string[] { "CHOPS", "HANAR", "SUPRD", "TOMSP", "VINET" })[new Random().Next(5)], | ||
Freight = 1.1 * x, | ||
OrderDate = DateTime.Now.AddDays(-x), | ||
}).ToList(); | ||
Orders.Add(new OrderData(10248, "VINET", 32.38, new DateTime(1996, 7, 4))); | ||
Orders.Add(new OrderData(10249, "TOMSP", 11.61, new DateTime(1996, 7, 5))); | ||
Orders.Add(new OrderData(10250, "HANAR", 65.83, new DateTime(1996, 7, 6))); | ||
Orders.Add(new OrderData(10251, "VINET", 41.34, new DateTime(1996, 7, 7))); | ||
Orders.Add(new OrderData(10252, "SUPRD", 151.30, new DateTime(1996, 7, 8))); | ||
Orders.Add(new OrderData(10253, "HANAR", 58.17, new DateTime(1996, 7, 9))); | ||
Orders.Add(new OrderData(10254, "CHOPS", 22.98, new DateTime(1996, 7, 10))); | ||
} | ||
return Orders; | ||
} | ||
public class Order | ||
|
||
public static List<OrderData> GetNewRecords() | ||
{ | ||
public int? OrderID { get; set; } | ||
public string CustomerID { get; set; } | ||
public DateTime? OrderDate { get; set; } | ||
public double? Freight { get; set; } | ||
return new List<OrderData> | ||
{ | ||
new OrderData(20001, "ALFKI", 21.50, DateTime.Now.AddDays(-1)), | ||
new OrderData(20002, "ANATR", 42.75, DateTime.Now.AddDays(-2)), | ||
new OrderData(20003, "ANTON", 17.00, DateTime.Now.AddDays(-3)), | ||
new OrderData(20004, "BERGS", 65.20, DateTime.Now.AddDays(-4)) | ||
}; | ||
} | ||
|
||
public int OrderID { get; set; } | ||
public string CustomerID { get; set; } | ||
public double Freight { get; set; } | ||
public DateTime? OrderDate { get; set; } | ||
} | ||
``` | ||
|
||
The following GIF represents DataGrid data source modified dynamically on button click, | ||
{% previewsample "https://blazorplayground.syncfusion.com/embed/rDhIXeCHJywphWgL?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %} | ||
|
||
 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.