Skip to content

Commit 46152c9

Browse files
csharpfritzCopilot
andcommitted
refactor: align GridView + ListView samples with SharedSampleObjects
- Created Employee model in SharedSampleObjects for GridView DisplayProperties - Added Product.GetProducts(count) overload for deterministic large datasets - GridView InlineEditing/Paging/Sorting/Selection/DisplayProperties now use shared models - ListView CrudOperations now uses Widget.SimpleWidgetList - 6 files aligned, all builds pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 908bc8e commit 46152c9

8 files changed

Lines changed: 59 additions & 111 deletions

File tree

samples/AfterBlazorServerSide/Components/Pages/ControlSamples/GridView/DisplayProperties.razor

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/ControlSamples/GridView/DisplayProperties"
22
@using BlazorWebFormsComponents.Enums
3+
@using SharedSampleObjects.Models
34

45
<PageTitle>GridView Display Properties</PageTitle>
56

@@ -97,20 +98,7 @@
9798
private bool _showHeader = true;
9899
private bool _showFooter = false;
99100

100-
private List<Employee> _employees = new()
101-
{
102-
new Employee { Id = 1, Name = "Alice Johnson", Department = "Engineering" },
103-
new Employee { Id = 2, Name = "Bob Smith", Department = "Marketing" },
104-
new Employee { Id = 3, Name = "Carol White", Department = "Engineering" },
105-
new Employee { Id = 4, Name = "Dave Brown", Department = "Sales" }
106-
};
101+
private List<Employee> _employees = Employee.GetEmployees();
107102

108103
private List<Employee> _emptyList = new();
109-
110-
private class Employee
111-
{
112-
public int Id { get; set; }
113-
public string Name { get; set; }
114-
public string Department { get; set; }
115-
}
116104
}

samples/AfterBlazorServerSide/Components/Pages/ControlSamples/GridView/InlineEditing.razor

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/ControlSamples/GridView/InlineEditing"
2+
@using SharedSampleObjects.Models
23

34
<PageTitle>GridView - Inline Editing</PageTitle>
45

@@ -29,17 +30,7 @@
2930

3031
protected override void OnInitialized()
3132
{
32-
Products = new List<Product>
33-
{
34-
new Product { Id = 1, Name = "Laptop Stand", Price = 29.99m },
35-
new Product { Id = 2, Name = "USB Cable", Price = 9.99m },
36-
new Product { Id = 3, Name = "Wireless Mouse", Price = 24.99m },
37-
new Product { Id = 4, Name = "Notebook", Price = 5.99m },
38-
new Product { Id = 5, Name = "Pen Set", Price = 12.99m },
39-
new Product { Id = 6, Name = "Monitor Arm", Price = 49.99m },
40-
new Product { Id = 7, Name = "Headphones", Price = 39.99m },
41-
new Product { Id = 8, Name = "Desk Lamp", Price = 19.99m }
42-
};
33+
Products = Product.GetProducts();
4334
}
4435

4536
private void HandleRowEditing(GridViewEditEventArgs e)
@@ -67,11 +58,4 @@
6758
}
6859
EditIndex = -1;
6960
}
70-
71-
public class Product
72-
{
73-
public int Id { get; set; }
74-
public string Name { get; set; }
75-
public decimal Price { get; set; }
76-
}
7761
}
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/ControlSamples/GridView/Paging"
2+
@using SharedSampleObjects.Models
23

34
<PageTitle>GridView - Paging</PageTitle>
45

@@ -17,20 +18,10 @@
1718
private int CurrentPage = 0;
1819
private int TotalPages => (int)Math.Ceiling((double)Products.Count / 10);
1920

20-
private List<Product> Products = Enumerable.Range(1, 50)
21-
.Select(i => new Product { Id = i, Name = $"Product {i}", Price = 9.99m + i, Category = i % 3 == 0 ? "Electronics" : i % 3 == 1 ? "Books" : "Clothing" })
22-
.ToList();
21+
private List<Product> Products = Product.GetProducts(50);
2322

2423
private void HandlePageChanged(PageChangedEventArgs e)
2524
{
2625
CurrentPage = e.NewPageIndex;
2726
}
28-
29-
public class Product
30-
{
31-
public int Id { get; set; }
32-
public string Name { get; set; }
33-
public decimal Price { get; set; }
34-
public string Category { get; set; }
35-
}
3627
}

samples/AfterBlazorServerSide/Components/Pages/ControlSamples/GridView/Selection.razor

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/ControlSamples/GridView/Selection"
22
@using BlazorWebFormsComponents.Enums
3+
@using SharedSampleObjects.Models
34

45
<PageTitle>GridView Selection</PageTitle>
56

@@ -91,20 +92,5 @@
9192
_selectionCount++;
9293
}
9394

94-
private List<Product> _products = new()
95-
{
96-
new Product { Id = 1, Name = "Widget A", Category = "Hardware", Price = 29.99m },
97-
new Product { Id = 2, Name = "Gadget B", Category = "Electronics", Price = 49.99m },
98-
new Product { Id = 3, Name = "Tool C", Category = "Hardware", Price = 19.99m },
99-
new Product { Id = 4, Name = "Device D", Category = "Electronics", Price = 99.99m },
100-
new Product { Id = 5, Name = "Part E", Category = "Accessories", Price = 9.99m }
101-
};
102-
103-
private class Product
104-
{
105-
public int Id { get; set; }
106-
public string Name { get; set; }
107-
public string Category { get; set; }
108-
public decimal Price { get; set; }
109-
}
95+
private List<Product> _products = Product.GetProducts().Take(5).ToList();
11096
}
Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/ControlSamples/GridView/Sorting"
22
@using BlazorWebFormsComponents.Enums
3+
@using SharedSampleObjects.Models
34

45
<PageTitle>GridView - Sorting</PageTitle>
56

@@ -31,15 +32,7 @@
3132

3233
protected override void OnInitialized()
3334
{
34-
Products = Enumerable.Range(1, 25)
35-
.Select(i => new Product
36-
{
37-
Id = i,
38-
Name = GetProductName(i),
39-
Price = Math.Round(4.99m + (i * 1.5m), 2),
40-
Category = i % 3 == 0 ? "Electronics" : i % 3 == 1 ? "Books" : "Clothing"
41-
})
42-
.ToList();
35+
Products = Product.GetProducts(25);
4336
}
4437

4538
private void HandleSorting(GridViewSortEventArgs e)
@@ -61,42 +54,4 @@
6154
_ => Products
6255
};
6356
}
64-
65-
private static string GetProductName(int index) => index switch
66-
{
67-
1 => "Laptop Stand",
68-
2 => "USB Cable",
69-
3 => "Wireless Mouse",
70-
4 => "Notebook",
71-
5 => "Pen Set",
72-
6 => "Monitor Arm",
73-
7 => "Headphones",
74-
8 => "Desk Lamp",
75-
9 => "Keyboard",
76-
10 => "Webcam",
77-
11 => "Phone Case",
78-
12 => "Tablet Cover",
79-
13 => "Charger",
80-
14 => "Backpack",
81-
15 => "Water Bottle",
82-
16 => "Speaker",
83-
17 => "Mouse Pad",
84-
18 => "Screen Protector",
85-
19 => "Power Bank",
86-
20 => "Cable Organizer",
87-
21 => "Stylus Pen",
88-
22 => "Card Reader",
89-
23 => "USB Hub",
90-
24 => "Desk Mat",
91-
25 => "Wrist Rest",
92-
_ => $"Product {index}"
93-
};
94-
95-
public class Product
96-
{
97-
public int Id { get; set; }
98-
public string Name { get; set; }
99-
public decimal Price { get; set; }
100-
public string Category { get; set; }
101-
}
10257
}

samples/AfterBlazorServerSide/Components/Pages/ControlSamples/ListView/CrudOperations.razor

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/ControlSamples/ListView/CrudOperations"
22
@using BlazorWebFormsComponents.Enums
3+
@using System.Linq
34

45
<h2>ListView CRUD Operations</h2>
56

@@ -85,12 +86,13 @@
8586
{
8687
if (firstRender)
8788
{
88-
items = new List<Widget>
89+
items = Widget.SimpleWidgetList.Take(3).Select(w => new Widget
8990
{
90-
new Widget { Id = 1, Name = "Alpha Widget", Price = 9.99M, LastUpdate = DateTime.Today },
91-
new Widget { Id = 2, Name = "Beta Widget", Price = 19.99M, LastUpdate = DateTime.Today },
92-
new Widget { Id = 3, Name = "Gamma Widget", Price = 29.99M, LastUpdate = DateTime.Today }
93-
};
91+
Id = w.Id,
92+
Name = w.Name,
93+
Price = w.Price,
94+
LastUpdate = w.LastUpdate
95+
}).ToList();
9496
listView.DataSource = items;
9597
listView.DataBind();
9698
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
3+
namespace SharedSampleObjects.Models
4+
{
5+
public class Employee
6+
{
7+
public int Id { get; set; }
8+
9+
public string Name { get; set; }
10+
11+
public string Department { get; set; }
12+
13+
public static List<Employee> GetEmployees()
14+
{
15+
return new List<Employee>
16+
{
17+
new Employee { Id = 1, Name = "Alice Johnson", Department = "Engineering" },
18+
new Employee { Id = 2, Name = "Bob Smith", Department = "Marketing" },
19+
new Employee { Id = 3, Name = "Carol White", Department = "Engineering" },
20+
new Employee { Id = 4, Name = "Dave Brown", Department = "Sales" }
21+
};
22+
}
23+
}
24+
}

samples/SharedSampleObjects/Models/Product.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,23 @@ public static List<Product> GetProducts()
3030
new Product { Id = 10, Name = "Mechanism", Price = 18.50m, Category = "Electronics", InStock = true }
3131
};
3232
}
33+
34+
public static List<Product> GetProducts(int count)
35+
{
36+
var categories = new[] { "Tools", "Electronics", "Hardware" };
37+
var products = new List<Product>();
38+
for (var i = 1; i <= count; i++)
39+
{
40+
products.Add(new Product
41+
{
42+
Id = i,
43+
Name = $"Product {i}",
44+
Price = System.Math.Round(4.99m + (i * 1.5m), 2),
45+
Category = categories[(i - 1) % 3],
46+
InStock = i % 3 != 0
47+
});
48+
}
49+
return products;
50+
}
3351
}
3452
}

0 commit comments

Comments
 (0)