Skip to content

Commit ed7d33f

Browse files
Merge pull request #2 from SyncfusionExamples/GH-3725-DataGrid
Sample(GH-3725): Auto generate column in blazor data grid
2 parents d2c3d47 + 1cb794c commit ed7d33f

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

Blazor_WebAssembly/Data_Annotations/Pages/Index.razor

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
@using System.ComponentModel.DataAnnotations;
55
@using System.ComponentModel;
66

7-
<SfGrid TValue="OrderDetails" DataSource="@Orders" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })">
7+
<SfGrid TValue="Order" DataSource="@Orders" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })">
88
<GridEditSettings AllowEditing="true" />
99
</SfGrid>
1010

1111
@code
1212
{
13-
public List<OrderDetails>? Orders { get; set; }
13+
public List<Order>? Orders { get; set; }
1414
protected override void OnInitialized()
1515
{
1616
base.OnInitialized();
1717
Orders = Enumerable.Range(1, 10).Select(x => new OrderDetails()
1818
{
1919
OrderID = 10240 + x,
20-
CustomerName = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
20+
Name = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
2121
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
2222
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
2323
OrderDate = DateTime.Now.AddDays(x),
2424
}).ToList();
2525
}
26-
public class OrderDetails
26+
public class Order
2727
{
2828
//Denotes one or more properties that uniquely identify an entity.
2929
[Key]
@@ -32,17 +32,17 @@
3232
public int? OrderID { get; set; }
3333

3434
[Display(Name = "CustomerName")]
35-
public string? CustomerName { get; set; }
36-
37-
//Specifies how data fields are displayed and formatted by ASP.NET dynamic data
38-
[DisplayFormat(DataFormatString = "c2")]
39-
public float Freight { get; set; }
35+
public string? Name { get; set; }
4036

4137
//Specifies whether the property this attribute is bound to be read only.
4238
[ReadOnly(true)]
4339
[Display(Name = "Ship City", AutoGenerateField = true, Order = 3)]
4440
public string? ShipCity { get; set; }
4541

42+
//Specifies how data fields are displayed and formatted by ASP.NET dynamic data
43+
[DisplayFormat(DataFormatString = "c2")]
44+
public float Freight { get; set; }
45+
4646
// Indicates whether the data field is editable.
4747
[Editable(false)]
4848
[Display(Name = "Order Date")]

Blazor_server/Data_Annotations/Pages/Index.razor

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
@using System.ComponentModel.DataAnnotations;
55
@using System.ComponentModel;
66

7-
<SfGrid TValue="OrderDetails" DataSource="@Orders" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })">
7+
<SfGrid TValue="Order" DataSource="@Orders" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })">
88
<GridEditSettings AllowEditing="true" />
99
</SfGrid>
1010

1111
@code
1212
{
13-
public List<OrderDetails>? Orders { get; set; }
13+
public List<Order>? Orders { get; set; }
1414
protected override void OnInitialized()
1515
{
1616
base.OnInitialized();
1717
Orders = Enumerable.Range(1, 10).Select(x => new OrderDetails()
1818
{
1919
OrderID = 10240 + x,
20-
CustomerName = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
20+
Name = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
2121
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
2222
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
2323
OrderDate = DateTime.Now.AddDays(x),
2424
}).ToList();
2525
}
26-
public class OrderDetails
26+
public class Order
2727
{
2828
//Denotes one or more properties that uniquely identify an entity.
2929
[Key]
@@ -32,17 +32,17 @@
3232
public int? OrderID { get; set; }
3333

3434
[Display(Name = "CustomerName")]
35-
public string? CustomerName { get; set; }
36-
37-
//Specifies how data fields are displayed and formatted by ASP.NET dynamic data
38-
[DisplayFormat(DataFormatString = "c2")]
39-
public float Freight { get; set; }
35+
public string? Name { get; set; }
4036

4137
//Specifies whether the property this attribute is bound to be read only.
4238
[ReadOnly(true)]
4339
[Display(Name = "Ship City", AutoGenerateField = true, Order = 3)]
4440
public string? ShipCity { get; set; }
4541

42+
//Specifies how data fields are displayed and formatted by ASP.NET dynamic data
43+
[DisplayFormat(DataFormatString = "c2")]
44+
public float Freight { get; set; }
45+
4646
// Indicates whether the data field is editable.
4747
[Editable(false)]
4848
[Display(Name = "Order Date")]

0 commit comments

Comments
 (0)