Skip to content

Commit f026b0a

Browse files
authored
List view grouping #25 (#87)
1 parent 3ef81d5 commit f026b0a

File tree

14 files changed

+452
-58
lines changed

14 files changed

+452
-58
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
@page "/ControlSamples/ListView/Grouping"
2+
3+
<h2>ListView Grouping Sample</h2>
4+
5+
<Nav />
6+
7+
<p>Here is a listview of 8 items grouped into 3's</p>
8+
9+
<table class="table">
10+
<thead>
11+
<tr>
12+
<td>Id</td>
13+
<td>Name</td>
14+
<td>Price</td>
15+
<td>Last Update</td>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<ListView @ref="simpleListView"
20+
runat="server"
21+
EnableViewState="false"
22+
GroupItemCount="3"
23+
Context="Item"
24+
ItemType="SharedSampleObjects.Models.Widget">
25+
<ItemTemplate>
26+
<tr>
27+
<td>@Item.Id</td>
28+
<td>@Item.Name</td>
29+
<td>@Item.Price.ToString("c")</td>
30+
<td>@Item.LastUpdate.ToString("d")</td>
31+
</tr>
32+
</ItemTemplate>
33+
<AlternatingItemTemplate>
34+
<tr class="table-dark"> <td>@Item.Id</td> <td>@Item.Name</td> <td>@Item.Price.ToString("c")</td> <td>@Item.LastUpdate.ToString("d")</td> </tr>
35+
</AlternatingItemTemplate>
36+
<GroupTemplate Context="ItemPlaceHolder">
37+
<tr><td colspan="4">GroupStart</td></tr>
38+
@ItemPlaceHolder
39+
<tr><td colspan="4">GroupEnd</td></tr>
40+
</GroupTemplate>
41+
<GroupSeparatorTemplate>
42+
<tr><td colspan="4">GroupingSeperator</td></tr>
43+
</GroupSeparatorTemplate>
44+
<EmptyDataTemplate>
45+
<tr>
46+
<td colspan="4">No widgets available</td>
47+
</tr>
48+
</EmptyDataTemplate>
49+
</ListView>
50+
</tbody>
51+
</table>
52+
53+
@code {
54+
55+
BlazorWebFormsComponents.ListView<Widget> simpleListView { get; set; }
56+
57+
protected override void OnAfterRender(bool firstRender)
58+
{
59+
60+
if (firstRender)
61+
{
62+
simpleListView.DataSource = Widget.Widgets(8);
63+
simpleListView.DataBind();
64+
}
65+
66+
//base.OnParametersSet();
67+
base.OnAfterRender(firstRender);
68+
69+
}
70+
71+
}
72+
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div>
22
Other usage samples:
3-
<NavLink href="/ControlSamples/ListView" class="component-link" Match="NavLinkMatch.All">Simple List View </NavLink> |
4-
<NavLink href="./ControlSamples/ListView/ModelBinding" class="component-link" Match="NavLinkMatch.All">ModelBinding Sample</NavLink>
3+
<NavLink href="./ControlSamples/ListView" class="component-link" Match="NavLinkMatch.All">Simple List View </NavLink> |
4+
<NavLink href="./ControlSamples/ListView/ModelBinding" class="component-link" Match="NavLinkMatch.All">ModelBinding Sample</NavLink> |
5+
<NavLink href="./ControlSamples/ListView/Grouping" class="component-link" Match="NavLinkMatch.All">Grouping Sample</NavLink> |
56
<NavLink href="./ControlSamples/ListView/LayoutTest" class="component-link" Match="NavLinkMatch.All">Layout Test</NavLink>
67
</div>

samples/AfterBlazorServerSide/Shared/NavMenu.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<TreeNode Text="ListView" NavigateUrl="/ControlSamples/ListView" Expanded="false">
2929
<TreeNode NavigateUrl="/ControlSamples/ListView" Text="Simple List View"></TreeNode>
3030
<TreeNode NavigateUrl="./ControlSamples/ListView/ModelBinding" Text="ModelBinding Sample"></TreeNode>
31+
<TreeNode NavigateUrl="./ControlSamples/ListView/Grouping" Text="Grouping Sample"></TreeNode>
3132
<TreeNode NavigateUrl="./ControlSamples/ListView/LayoutTest" Text="Layout Test"></TreeNode>
3233
</TreeNode>
3334

samples/BeforeWebForms/BeforeWebForms.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
<Content Include="ControlSamples\DataList\StyleAttributes.aspx" />
115115
<Content Include="ControlSamples\DataList\FlowLayout.aspx" />
116116
<Content Include="ControlSamples\DataList\Default.aspx" />
117+
<Content Include="ControlSamples\ListView\Grouping.aspx" />
117118
<Content Include="ControlSamples\ListView\Default.aspx" />
118119
<Content Include="ControlSamples\ListView\ModelBinding.aspx" />
119120
<Content Include="ControlSamples\Repeater\Default.aspx" />
@@ -197,6 +198,13 @@
197198
<Compile Include="ControlSamples\DataList\Default.aspx.designer.cs">
198199
<DependentUpon>Default.aspx</DependentUpon>
199200
</Compile>
201+
<Compile Include="ControlSamples\ListView\Grouping.aspx.cs">
202+
<DependentUpon>Grouping.aspx</DependentUpon>
203+
<SubType>ASPXCodeBehind</SubType>
204+
</Compile>
205+
<Compile Include="ControlSamples\ListView\Grouping.aspx.designer.cs">
206+
<DependentUpon>Grouping.aspx</DependentUpon>
207+
</Compile>
200208
<Compile Include="ControlSamples\ListView\Default.aspx.cs">
201209
<DependentUpon>Default.aspx</DependentUpon>
202210
<SubType>ASPXCodeBehind</SubType>

samples/BeforeWebForms/ControlSamples/ListView/Default.aspx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h2>ListView control homepage</h2>
66

77
<div>
8-
Other usage samples: <a href="ModelBinding.aspx">ModelBinding Sample</a>
8+
<a href="Default.aspx">Default</a> | <a href="Grouping.aspx">Grouping</a> | <a href="ModelBinding.aspx">ModelBinding</a>
99
</div>
1010

1111
<p>Here is a simple listview bound to a collection of widgets.</p>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grouping.aspx.cs" Inherits="BeforeWebForms.ControlSamples.ListView.Grouping" MasterPageFile="~/Site.Master" %>
2+
3+
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
4+
5+
<h2>ListView control homepage</h2>
6+
7+
<div>
8+
<a href="Default.aspx">Default</a> | <a href="Grouping.aspx">Grouping</a> | <a href="ModelBinding.aspx">ModelBinding</a>
9+
</div>
10+
11+
<p>Here is a listview using Grouping to interact with widgets.</p>
12+
13+
<asp:ListView ID="simpleListView"
14+
runat="server"
15+
GroupItemCount="2"
16+
ItemType="SharedSampleObjects.Models.Widget">
17+
<LayoutTemplate>
18+
<table>
19+
<thead>
20+
<tr>
21+
<td>Id</td>
22+
<td>Name</td>
23+
<td>Price</td>
24+
<td>Last Update</td>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
<tr runat="server" id="groupPlaceHolder"></tr>
29+
</tbody>
30+
</table>
31+
</LayoutTemplate>
32+
<GroupTemplate>
33+
<tr><td colspan="4">GroupStart</td></tr>
34+
<data runat="server" id="itemPlaceHolder" />
35+
<tr><td colspan="4">GroupEnd</td></tr>
36+
</GroupTemplate>
37+
<GroupSeparatorTemplate>
38+
<tr runat="server"> <td colspan="4">GroupingSeperator</td> </tr>
39+
</GroupSeparatorTemplate>
40+
<ItemTemplate>
41+
<tr>
42+
<td><%# Item.Id %></td>
43+
<td><%# Item.Name %></td>
44+
<td><%# Item.Price.ToString("c") %></td>
45+
<td><%# Item.LastUpdate.ToString("d") %></td>
46+
</tr>
47+
</ItemTemplate>
48+
<EmptyDataTemplate>
49+
<tr>
50+
<td colspan="4">No widgets available</td>
51+
</tr>
52+
</EmptyDataTemplate>
53+
<EmptyItemTemplate></EmptyItemTemplate>
54+
</asp:ListView>
55+
56+
57+
</asp:Content>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using SharedSampleObjects.Models;
2+
using System;
3+
using System.Linq;
4+
5+
namespace BeforeWebForms.ControlSamples.ListView
6+
{
7+
public partial class Grouping : System.Web.UI.Page
8+
{
9+
protected void Page_Load(object sender, EventArgs e)
10+
{
11+
simpleListView.DataSource = Widget.Widgets(8)
12+
.Select((x, i) => new Widget
13+
{
14+
Id= x.Id,
15+
Name = x.Name,
16+
LastUpdate = x.LastUpdate,
17+
Price = i % 2
18+
}).ToArray();
19+
simpleListView.DataBind();
20+
}
21+
}
22+
}

samples/BeforeWebForms/ControlSamples/ListView/Grouping.aspx.designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/BeforeWebForms/ControlSamples/ListView/ModelBinding.aspx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
44

5-
<h2>ListView ModelBinding Sample</h2>
5+
<h2>ListView control homepage</h2>
6+
7+
<div>
8+
<a href="Default.aspx">Default</a> | <a href="Grouping.aspx">Grouping</a> | <a href="ModelBinding.aspx">ModelBinding</a>
9+
</div>
610

711
<p>Here is a listview using ModelBinding to interact with widgets.</p>
812

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
@inherits TestComponentBase
2+
3+
<Fixture Test="FirstTest">
4+
<ComponentUnderTest>
5+
<table>
6+
<thead> <tr> <td>Id</td> <td>Name</td> <td>Price</td> <td>Last Update</td> </tr> </thead>
7+
<tbody>
8+
<ListView Items="data"
9+
GroupItemCount="3"
10+
ItemType="Widget"
11+
Context="Item">
12+
<ItemTemplate>
13+
<tr> <td>@Item.Id</td> <td>@Item.Name</td> <td>@Item.Price</td> <td>@Item.LastUpdate.ToString("d")</td> </tr>
14+
</ItemTemplate>
15+
<GroupTemplate Context="ItemPlaceHolder">
16+
<tr><td colspan="4">GroupStart</td></tr>
17+
@ItemPlaceHolder
18+
<tr><td colspan="4">GroupEnd</td></tr>
19+
</GroupTemplate>
20+
<GroupSeparatorTemplate>
21+
<tr><td colspan="4">GroupingSeperator</td></tr>
22+
</GroupSeparatorTemplate>
23+
</ListView>
24+
</tbody>
25+
</table>
26+
</ComponentUnderTest>
27+
</Fixture>
28+
29+
@code{
30+
public Widget[] data = Widget.Widgets(7)
31+
.Select((x, i) => new Widget
32+
{
33+
Id = x.Id,
34+
Name = x.Name,
35+
LastUpdate = x.LastUpdate,
36+
Price = i % 2
37+
}).ToArray();
38+
}
39+
40+
@code {
41+
void FirstTest()
42+
{
43+
44+
var cut = GetComponentUnderTest();
45+
Console.WriteLine(cut.Markup);
46+
47+
48+
// 8 x 2 => I I G I I G I I G I I
49+
// 8 x 3 => I I I G I I I G I I
50+
// 7 x 3 => I I I G I I I G I
51+
52+
cut.FindAll("td").Count(e => e.TextContent.Contains("Widget")).ShouldBe(7);
53+
cut.FindAll("td").Count(e => e.TextContent.Contains("GroupingSeperator")).ShouldBe(2);
54+
cut.FindAll("td").Count(e => e.TextContent.Contains("GroupStart")).ShouldBe(3);
55+
cut.FindAll("td").Count(e => e.TextContent.Contains("GroupEnd")).ShouldBe(3);
56+
}
57+
}
58+
59+
@*
60+
<table>
61+
<thead>
62+
<tr> <td>Id</td> <td>Name</td> <td>Price</td> <td>Last Update</td> </tr>
63+
</thead>
64+
<tbody>
65+
<tr><td colspan="4">GroupStart</td></tr>
66+
<tr> <td>1</td> <td>one Widget</td> <td>£0.00</td> <td>11/02/2020</td> </tr>
67+
<tr> <td>2</td> <td>two Widget</td> <td>£1.00</td> <td>03/02/2020</td> </tr>
68+
<tr> <td>3</td> <td>three Widget</td> <td>£0.00</td> <td>11/02/2020</td> </tr>
69+
<tr><td colspan="4">GroupEnd</td></tr>
70+
<tr> <td colspan="4">GroupingSeperator</td> </tr>
71+
<tr><td colspan="4">GroupStart</td></tr>
72+
<tr> <td>4</td> <td>four Widget</td> <td>£1.00</td> <td>12/02/2020</td> </tr>
73+
<tr> <td>5</td> <td>five Widget</td> <td>£0.00</td> <td>10/02/2020</td> </tr>
74+
<tr> <td>6</td> <td>six Widget</td> <td>£1.00</td> <td>10/02/2020</td> </tr>
75+
<tr><td colspan="4">GroupEnd</td></tr>
76+
<tr> <td colspan="4">GroupingSeperator</td> </tr>
77+
<tr><td colspan="4">GroupStart</td></tr>
78+
<tr> <td>7</td> <td>seven Widget</td> <td>£0.00</td> <td>08/02/2020</td> </tr>
79+
<tr><td colspan="4">GroupEnd</td></tr>
80+
</tbody>
81+
</table>
82+
*@

0 commit comments

Comments
 (0)