Skip to content

Commit 9dc9eba

Browse files
Merge pull request #8 from SyncfusionExamples/GH-3725-Annotaion
Sample(GH-3725): AutoGenerate columns sample in server and wasm
2 parents fe7b83f + dea9a7a commit 9dc9eba

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@page "/"
22

33
@using Syncfusion.Blazor.Grids;
4-
@using System.ComponentModel.DataAnnotations;
54
@using System.ComponentModel;
5+
@using System.ComponentModel.DataAnnotations;
66

77
<SfGrid TValue="Order" DataSource="@Orders" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })">
88
<GridEditSettings AllowEditing="true" />
@@ -11,41 +11,47 @@
1111
@code
1212
{
1313
public List<Order>? Orders { get; set; }
14+
1415
protected override void OnInitialized()
1516
{
1617
base.OnInitialized();
1718
Orders = Enumerable.Range(1, 10).Select(x => new Order()
18-
{
19-
OrderID = 10240 + x,
20-
Name = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
21-
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
22-
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
23-
OrderDate = DateTime.Now.AddDays(x),
24-
}).ToList();
19+
{
20+
OrderID = 10240 + x,
21+
Name = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
22+
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
23+
CustomerID = 10000 + x,
24+
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
25+
OrderDate = DateTime.Now.AddDays(x)
26+
}).ToList();
2527
}
28+
2629
public class Order
2730
{
2831
//Denotes one or more properties that uniquely identify an entity.
2932
[Key]
30-
//Sets the header text to the column.
31-
[Display(Name = "Order ID")]
3233
public int? OrderID { get; set; }
3334

34-
[Display(Name = "CustomerName", Order = 1)]
35-
public string? Name { get; set; }
36-
3735
//Specifies whether the property this attribute is bound to be read only.
3836
[ReadOnly(true)]
39-
[Display(Name = "Ship City", AutoGenerateField = true)]
37+
//Sets the header text to the column.
38+
[Display(Name = "Customer Name", Order = 1)]
39+
public string? Name { get; set; }
40+
41+
//Gets or sets whether UI should be generated automatically to display this field
42+
[Display(AutoGenerateField = false)]
43+
public int? CustomerID { get; set; }
44+
45+
//Gets or sets the order in which this field should be displayed
46+
[Display(Order = 4)]
4047
public string? ShipCity { get; set; }
4148

49+
[Display(Order = 3)]
4250
//Specifies how data fields are displayed and formatted by ASP.NET dynamic data
4351
[DisplayFormat(DataFormatString = "c2")]
4452
public float Freight { get; set; }
4553

46-
// Indicates whether the data field is editable.
47-
[Editable(false)]
48-
[Display(Name = "Order Date")]
54+
[Display(Order = 2)]
4955
public DateTime? OrderDate { get; set; }
5056
}
5157
}
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@page "/"
22

33
@using Syncfusion.Blazor.Grids;
4-
@using System.ComponentModel.DataAnnotations;
54
@using System.ComponentModel;
5+
@using System.ComponentModel.DataAnnotations;
66

77
<SfGrid TValue="Order" DataSource="@Orders" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })">
88
<GridEditSettings AllowEditing="true" />
@@ -11,41 +11,47 @@
1111
@code
1212
{
1313
public List<Order>? Orders { get; set; }
14+
1415
protected override void OnInitialized()
1516
{
1617
base.OnInitialized();
1718
Orders = Enumerable.Range(1, 10).Select(x => new Order()
18-
{
19-
OrderID = 10240 + x,
20-
Name = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
21-
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
22-
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
23-
OrderDate = DateTime.Now.AddDays(x),
24-
}).ToList();
19+
{
20+
OrderID = 10240 + x,
21+
Name = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
22+
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
23+
CustomerID = 10000 + x,
24+
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
25+
OrderDate = DateTime.Now.AddDays(x)
26+
}).ToList();
2527
}
28+
2629
public class Order
2730
{
2831
//Denotes one or more properties that uniquely identify an entity.
2932
[Key]
30-
//Sets the header text to the column.
31-
[Display(Name = "Order ID")]
3233
public int? OrderID { get; set; }
3334

34-
[Display(Name = "CustomerName", Order = 1)]
35-
public string? Name { get; set; }
36-
3735
//Specifies whether the property this attribute is bound to be read only.
3836
[ReadOnly(true)]
39-
[Display(Name = "Ship City", AutoGenerateField = true)]
37+
//Sets the header text to the column.
38+
[Display(Name = "Customer Name", Order = 1)]
39+
public string? Name { get; set; }
40+
41+
//Gets or sets whether UI should be generated automatically to display this field
42+
[Display(AutoGenerateField = false)]
43+
public int? CustomerID { get; set; }
44+
45+
//Gets or sets the order in which this field should be displayed
46+
[Display(Order = 4)]
4047
public string? ShipCity { get; set; }
4148

49+
[Display(Order = 3)]
4250
//Specifies how data fields are displayed and formatted by ASP.NET dynamic data
4351
[DisplayFormat(DataFormatString = "c2")]
4452
public float Freight { get; set; }
4553

46-
// Indicates whether the data field is editable.
47-
[Editable(false)]
48-
[Display(Name = "Order Date")]
54+
[Display(Order = 2)]
4955
public DateTime? OrderDate { get; set; }
5056
}
5157
}

0 commit comments

Comments
 (0)