Skip to content

Commit 634a443

Browse files
author
Joe Harrison
committed
documentation and demos
1 parent e62fe44 commit 634a443

3 files changed

Lines changed: 77 additions & 72 deletions

File tree

MVCGridExample/App_Start/MVCGridConfig.cs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,45 @@ public class MVCGridConfig
1515
{
1616
public static void RegisterGrids()
1717
{
18-
MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>()
18+
ColumnDefaults colDefauls = new ColumnDefaults()
19+
{
20+
EnableSorting = true
21+
};
22+
23+
MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>(colDefauls)
1924
.WithAuthorizationType(AuthorizationType.AllowAnonymous)
20-
.WithSorting(true, "Id", SortDirection.Dsc)
21-
.WithPaging(true, 10, true, 100)
25+
.WithSorting(sorting: true, defaultSortColumn: "Id", defaultSortDirection: SortDirection.Dsc)
26+
.WithPaging(paging: true, itemsPerPage: 10, allowChangePageSize: true, maxItemsPerPage: 100)
2227
.WithAdditionalQueryOptionNames("search")
2328
.AddColumns(cols =>
2429
{
25-
cols.Add(new GridColumn<Person>()
26-
{
27-
ColumnName = "Id",
28-
EnableSorting = true,
29-
HtmlEncode = false,
30-
ValueExpression = (p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }),
31-
ValueTemplate = "<a href='{Value}'>{Model.Id}</a>",
32-
PlainTextValueExpression = (p, c) => p.Id.ToString()
33-
});
30+
cols.Add("Id").WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
31+
.WithValueTemplate("<a href='{Value}'>{Model.Id}</a>", false)
32+
.WithPlainTextValueExpression(p => p.Id.ToString());
3433
cols.Add("FirstName").WithHeaderText("First Name")
35-
.WithSorting(true)
36-
.WithAllowChangeVisibility(true)
37-
.WithValueExpression((p, c) => p.FirstName);
34+
.WithVisibility(true, true)
35+
.WithValueExpression(p => p.FirstName);
3836
cols.Add("LastName").WithHeaderText("Last Name")
39-
.WithSorting(true)
40-
.WithAllowChangeVisibility(true)
41-
.WithValueExpression((p, c) => p.LastName);
37+
.WithVisibility(true, true)
38+
.WithValueExpression(p => p.LastName);
4239
cols.Add("FullName").WithHeaderText("Full Name")
4340
.WithValueTemplate("{Model.FirstName} {Model.LastName}")
44-
.WithVisibility(false)
45-
.WithAllowChangeVisibility(true)
41+
.WithVisibility(visible: false, allowChangeVisibility: true)
4642
.WithSorting(false);
4743
cols.Add("StartDate").WithHeaderText("Start Date")
48-
.WithSorting(true)
49-
.WithAllowChangeVisibility(true)
50-
.WithValueExpression((p, c) => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
44+
.WithVisibility(visible: true, allowChangeVisibility: true)
45+
.WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
5146
cols.Add("Status")
5247
.WithSortColumnData("Active")
53-
.WithSorting(true)
54-
.WithAllowChangeVisibility(true)
48+
.WithVisibility(visible: true, allowChangeVisibility: true)
5549
.WithHeaderText("Status")
56-
.WithValueExpression((p, c) => p.Active ? "Active" : "Inactive")
57-
.WithCellCssClassExpression((p, c) => p.Active ? "success" : "danger");
50+
.WithValueExpression(p => p.Active ? "Active" : "Inactive")
51+
.WithCellCssClassExpression(p => p.Active ? "success" : "danger");
5852
cols.Add("Gender").WithValueExpression((p, c) => p.Gender)
5953
.WithAllowChangeVisibility(true);
6054
cols.Add("Email")
61-
.WithVisibility(false)
62-
.WithAllowChangeVisibility(true)
63-
.WithValueExpression((p, c) => p.Email);
55+
.WithVisibility(visible: false, allowChangeVisibility: true)
56+
.WithValueExpression(p => p.Email);
6457
cols.Add("Url").WithVisibility(false)
6558
.WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }));
6659
})
@@ -111,11 +104,6 @@ public static void RegisterGrids()
111104
})
112105
);
113106

114-
ColumnDefaults colDefauls = new ColumnDefaults()
115-
{
116-
EnableSorting = true
117-
};
118-
119107
MVCGridDefinitionTable.Add("SortableGrid", new MVCGridBuilder<Person>(colDefauls)
120108
.WithAuthorizationType(AuthorizationType.AllowAnonymous)
121109
.AddColumns(cols =>

MVCGridExample/Content/MVCGridConfig.txt

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,45 @@ namespace MVCGridExample
1515
{
1616
public static void RegisterGrids()
1717
{
18-
MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>()
18+
ColumnDefaults colDefauls = new ColumnDefaults()
19+
{
20+
EnableSorting = true
21+
};
22+
23+
MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>(colDefauls)
1924
.WithAuthorizationType(AuthorizationType.AllowAnonymous)
20-
.WithSorting(true, "Id", SortDirection.Dsc)
21-
.WithPaging(true, 10, true, 100)
25+
.WithSorting(sorting: true, defaultSortColumn: "Id", defaultSortDirection: SortDirection.Dsc)
26+
.WithPaging(paging: true, itemsPerPage: 10, allowChangePageSize: true, maxItemsPerPage: 100)
2227
.WithAdditionalQueryOptionNames("search")
2328
.AddColumns(cols =>
2429
{
25-
cols.Add(new GridColumn<Person>()
26-
{
27-
ColumnName = "Id",
28-
EnableSorting = true,
29-
HtmlEncode = false,
30-
ValueExpression = (p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }),
31-
ValueTemplate = "<a href='{Value}'>{Model.Id}</a>",
32-
PlainTextValueExpression = (p, c) => p.Id.ToString()
33-
});
30+
cols.Add("Id").WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
31+
.WithValueTemplate("<a href='{Value}'>{Model.Id}</a>", false)
32+
.WithPlainTextValueExpression(p => p.Id.ToString());
3433
cols.Add("FirstName").WithHeaderText("First Name")
35-
.WithSorting(true)
36-
.WithAllowChangeVisibility(true)
37-
.WithValueExpression((p, c) => p.FirstName);
34+
.WithVisibility(true, true)
35+
.WithValueExpression(p => p.FirstName);
3836
cols.Add("LastName").WithHeaderText("Last Name")
39-
.WithSorting(true)
40-
.WithAllowChangeVisibility(true)
41-
.WithValueExpression((p, c) => p.LastName);
37+
.WithVisibility(true, true)
38+
.WithValueExpression(p => p.LastName);
4239
cols.Add("FullName").WithHeaderText("Full Name")
4340
.WithValueTemplate("{Model.FirstName} {Model.LastName}")
44-
.WithVisibility(false)
45-
.WithAllowChangeVisibility(true)
41+
.WithVisibility(visible: false, allowChangeVisibility: true)
4642
.WithSorting(false);
4743
cols.Add("StartDate").WithHeaderText("Start Date")
48-
.WithSorting(true)
49-
.WithAllowChangeVisibility(true)
50-
.WithValueExpression((p, c) => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
44+
.WithVisibility(visible: true, allowChangeVisibility: true)
45+
.WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
5146
cols.Add("Status")
5247
.WithSortColumnData("Active")
53-
.WithSorting(true)
54-
.WithAllowChangeVisibility(true)
48+
.WithVisibility(visible: true, allowChangeVisibility: true)
5549
.WithHeaderText("Status")
56-
.WithValueExpression((p, c) => p.Active ? "Active" : "Inactive")
57-
.WithCellCssClassExpression((p, c) => p.Active ? "success" : "danger");
50+
.WithValueExpression(p => p.Active ? "Active" : "Inactive")
51+
.WithCellCssClassExpression(p => p.Active ? "success" : "danger");
5852
cols.Add("Gender").WithValueExpression((p, c) => p.Gender)
5953
.WithAllowChangeVisibility(true);
6054
cols.Add("Email")
61-
.WithVisibility(false)
62-
.WithAllowChangeVisibility(true)
63-
.WithValueExpression((p, c) => p.Email);
55+
.WithVisibility(visible: false, allowChangeVisibility: true)
56+
.WithValueExpression(p => p.Email);
6457
cols.Add("Url").WithVisibility(false)
6558
.WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }));
6659
})
@@ -111,11 +104,6 @@ namespace MVCGridExample
111104
})
112105
);
113106

114-
ColumnDefaults colDefauls = new ColumnDefaults()
115-
{
116-
EnableSorting = true
117-
};
118-
119107
MVCGridDefinitionTable.Add("SortableGrid", new MVCGridBuilder<Person>(colDefauls)
120108
.WithAuthorizationType(AuthorizationType.AllowAnonymous)
121109
.AddColumns(cols =>

MVCGridExample/Views/Home/Index.cshtml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,43 @@
4545
{
4646
MVCGridName = "TestGrid",
4747
PageSize = true,
48-
ColumnVisibility = false,
49-
Export = false,
48+
ColumnVisibility = true,
49+
Export = true,
5050
GlobalSearch = true
5151
})
5252

5353
@Html.MVCGrid("TestGrid")
5454
</div>
5555
</div>
5656

57+
<p class="lead">Here is the view markup for the above grid:</p>
58+
<pre class="brush: js">
59+
&lt;div class=&quot;panel panel-default&quot;&gt;
60+
&lt;div class=&quot;panel-body&quot;&gt;
61+
62+
@@Html.Partial(&quot;_MVCGridToolbar&quot;, new MVCGridToolbarModel()
63+
{
64+
MVCGridName = &quot;TestGrid&quot;,
65+
PageSize = true,
66+
ColumnVisibility = true,
67+
Export = true,
68+
GlobalSearch = true
69+
})
70+
@@Html.MVCGrid(&quot;TestGrid&quot;)
71+
&lt;/div&gt;
72+
&lt;/div&gt;
73+
</pre>
74+
75+
<p class="lead">Below is the only code needed to query the data and display the grid:</p>
76+
77+
<div class="panel panel-default">
78+
<div class="panel-heading">Inside <strong>MVCGridConfig.cs</strong></div>
79+
<div class="panel-body">
80+
<pre class="brush: csharp">@CodeSnippetHelper.GetCodeSnippet("TestGrid")</pre>
81+
</div>
82+
</div>
83+
84+
85+
5786
@*<input type="button" value="Refresh" onclick="MVCGrid.reloadGrid('TestMapping');" />
5887
<input type="button" value="Export" onclick="location.href = MVCGrid.getExportUrl('TestMapping');" />*@

0 commit comments

Comments
 (0)