Skip to content

Commit e17818a

Browse files
authored
Merge pull request #102 from programcsharp/master-samples
Add button examples
2 parents 11f3440 + 8db6b60 commit e17818a

File tree

8 files changed

+154
-16
lines changed

8 files changed

+154
-16
lines changed

Griddly/Content/Site.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@ input[type="checkbox"].input-validation-error {
9999
overflow-y:hidden !important;
100100
padding: 10px 20px;
101101
margin: 0 0 20px;
102-
font-size: .8em !important;
103-
line-height: 1.25em !important;
102+
font-size: 0.95em !important;
104103
border-left: 5px solid #eee;
105104
}
106105

107106
.syntaxhighlighter .line
108107
{
109-
line-height: 1.25em !important;
110108
}
111109

112110
.dropdown-menu {

Griddly/Controllers/ExampleController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ public ActionResult Columns()
2121
});
2222
}
2323

24+
public ActionResult Buttons(string lastName = null)
25+
{
26+
ViewBag.LastName = lastName;
27+
28+
return View("Example", new ExampleModel()
29+
{
30+
Title = "Buttons Example",
31+
GridAction = "ButtonsGrid",
32+
ParentView = "Buttons.cshtml",
33+
GridView = "ButtonsGrid.cshtml",
34+
Description = ""
35+
});
36+
}
37+
2438
public ActionResult Filters()
2539
{
2640
return View("Example", new ExampleModel()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Griddly.Models;
2+
using Griddly.Mvc;
3+
using Griddly.Mvc.Results;
4+
using System.Linq;
5+
using System.Web.Mvc;
6+
7+
namespace Griddly.Controllers
8+
{
9+
public partial class ExampleController : Controller
10+
{
11+
public GriddlyResult ButtonsGrid(string lastName)
12+
{
13+
IQueryable<TestGridItem> query = _testData.AsQueryable();
14+
15+
if (lastName != null)
16+
query = query.Where(x => x.LastName.IndexOf(lastName, System.StringComparison.InvariantCultureIgnoreCase) > -1);
17+
18+
return new QueryableResult<TestGridItem>(query);
19+
}
20+
21+
[HttpPost]
22+
public ActionResult ButtonsPost(long[] ids)
23+
{
24+
ViewBag.Selected = _testData.AsQueryable()
25+
.Where(x => ids.Any(i => i == x.Id))
26+
.Select(x => $"{x.FirstName} {x.LastName}")
27+
.ToArray();
28+
29+
return Buttons();
30+
}
31+
32+
[HttpPost]
33+
public ActionResult ButtonsPostCriteria(string lastName)
34+
{
35+
return Buttons(lastName);
36+
}
37+
38+
public ActionResult ButtonsAjax(long id)
39+
{
40+
return Json(new
41+
{
42+
selected = _testData.AsQueryable()
43+
.Where(x => id == x.Id)
44+
.Select(x => $"{x.FirstName} {x.LastName}")
45+
.FirstOrDefault()
46+
});
47+
}
48+
49+
public ActionResult ButtonsAjaxBulk(long[] ids)
50+
{
51+
return Json(new
52+
{
53+
selected = string.Join(", ", _testData.AsQueryable()
54+
.Where(x => ids.Any(i => i == x.Id))
55+
.Select(x => $"{x.FirstName} {x.LastName}")
56+
.ToArray())
57+
});
58+
}
59+
}
60+
}

Griddly/Griddly.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
<Compile Include="App_Start\FilterConfig.cs" />
127127
<Compile Include="App_Start\RouteConfig.cs" />
128128
<Compile Include="Controllers\ExampleController.cs" />
129+
<Compile Include="Controllers\Examples\ButtonsGrid.cs">
130+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
131+
</Compile>
129132
<Compile Include="Controllers\Examples\ColumnsGrid.cs">
130133
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
131134
</Compile>
@@ -294,6 +297,8 @@
294297
<Content Include="Views\Example\Filters.cshtml" />
295298
<Content Include="Views\Example\FilterDefaultsGrid.cshtml" />
296299
<Content Include="Views\Example\FilterDefaults.cshtml" />
300+
<Content Include="Views\Example\Buttons.cshtml" />
301+
<Content Include="Views\Example\ButtonsGrid.cshtml" />
297302
</ItemGroup>
298303
<ItemGroup>
299304
<ProjectReference Include="..\Griddly.Mvc\Griddly.Mvc.csproj">
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<div class="alert alert-info" style="@(ViewBag.Selected == null ? "display:none;" : null)">
2+
<h4>You selected:</h4>
3+
<p>@(ViewBag.Selected != null ? string.Join(", ", ViewBag.Selected) : null)</p>
4+
</div>
5+
6+
@Html.Griddly("ButtonsGrid", new { lastName = ViewBag.LastName })
7+
8+
<div id="modal-id" class="modal fade">
9+
<div class="modal-dialog">
10+
<div class="modal-content">
11+
<div class="modal-body">
12+
<p>Hello world!</p>
13+
</div>
14+
<div class="modal-footer">
15+
<button class="btn btn-sm" data-dismiss="modal">Close</button>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
20+
21+
<script>
22+
function CallJavascriptFunction()
23+
{
24+
alert("Hello world! You may only call global javascript functions.");
25+
}
26+
27+
$(".griddly .btn").on("afterExecute", function (e, data)
28+
{
29+
if ($(".alert-info p").text().length)
30+
$(".alert-info p").append("<br />AND " + data.selected);
31+
else
32+
$(".alert-info p").append(data.selected);
33+
34+
$(".alert-info").show();
35+
});
36+
</script>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@{
2+
var gridSettings = new GriddlySettings<TestGridItem>()
3+
{
4+
PageSize = 20,
5+
RowClickUrl = x => "http://microsoft.com",
6+
EmptyGridMessageTemplate =@<text><div class="alert alert-warning">@item.Settings.EmptyGridMessage</div></text>,
7+
EmptyGridMessage = "Sorry, no records were found"
8+
};
9+
10+
gridSettings
11+
.SelectColumn(x => x.Id)
12+
.Column(x => x.Id)
13+
.Column(x => x.FirstName, "First Name")
14+
.Column(x => x.LastName, "Last Name", filter: x => x.FilterBox(FilterDataType.String, field: "lastName"))
15+
.Column(x => x.Address)
16+
.Column(x => x.City)
17+
.Column(x => x.State)
18+
.Column(x => x.PostalCode, "Zip")
19+
.Column(x => x.Quantity)
20+
.Column(x => x.Total, format: "c");
21+
22+
gridSettings.Button(Url.Action("Columns"), "Navigate")
23+
.ButtonSeparator()
24+
.Button(Url.Action("ButtonsPostCriteria"), "Post Filter Criteria", action: GriddlyButtonAction.PostCriteria)
25+
.Button("CallJavascriptFunction", "Call Javascript Function", action: GriddlyButtonAction.Javascript)
26+
.Button("modal-id", "Open A Modal", action: GriddlyButtonAction.Modal)
27+
.ButtonSeparator()
28+
.Button(Url.Action("ButtonsPost"), "Post All Selected", action: GriddlyButtonAction.Post)
29+
.Button(Url.Action("ButtonsAjax"), "Ajax Foreach Selected", action: GriddlyButtonAction.Ajax)
30+
.Button(Url.Action("ButtonsAjaxBulk"), "Ajax All Selected", action: GriddlyButtonAction.AjaxBulk);
31+
}
32+
33+
@Html.Griddly(gridSettings)

Griddly/Views/Example/Example.cshtml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
@{
33
ViewBag.Title = Model.Title;
44
}
5-
@section head {
6-
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/vs.min.css">
7-
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"></script>
8-
<script src="/scripts/cshtml-razor.js"></script>
9-
<script>
10-
hljs.registerLanguage('cshtml-razor', window.hljsDefineCshtmlRazor);
11-
hljs.initHighlightingOnLoad();
12-
</script>
13-
}
145

156
<div class="row">
167
<div class="col-md-12">
@@ -32,14 +23,14 @@
3223

3324
<div id="tab-view" class="tab-pane" role="tabpanel">
3425
<h3>Parent View (@Model.ParentView.ToLower())</h3>
35-
<pre><code class="cs razor-cshtml">@System.IO.File.ReadAllText(Context.Server.MapPath("~/Views/Example/" + Model.ParentView))</code></pre>
26+
<pre class="brush: razor">@System.IO.File.ReadAllText(Context.Server.MapPath("~/Views/Example/" + Model.ParentView))</pre>
3627

3728
<h3>Child View (@Model.GridView.ToLower())</h3>
38-
<pre><code class="cs razor-cshtml">@System.IO.File.ReadAllText(Context.Server.MapPath("~/Views/Example/" + Model.GridView))</code></pre>
29+
<pre class="brush: razor">@System.IO.File.ReadAllText(Context.Server.MapPath("~/Views/Example/" + Model.GridView))</pre>
3930
</div>
4031

4132
<div id="tab-action" class="tab-pane" role="tabpanel">
42-
<pre><code class="cs">@System.IO.File.ReadAllText(Context.Server.MapPath("~/Controllers/Examples/" + Model.GridAction + ".cs"))</code></pre>
33+
<pre class="brush: csharp">@System.IO.File.ReadAllText(Context.Server.MapPath("~/Controllers/Examples/" + Model.GridAction + ".cs"))</pre>
4334
</div>
4435

4536
</div>

Griddly/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" >Grid Examples <span class="caret"></span></a>
2929
<ul class="dropdown-menu">
3030
<li>@Html.ActionLink("Columns", "Columns", "Example")</li>
31+
<li>@Html.ActionLink("Buttons", "Buttons", "Example")</li>
3132
<li>@Html.ActionLink("Filters", "Filters", "Example")</li>
3233
<li>@Html.ActionLink("Filter Defaults", "FilterDefaults", "Example")</li>
3334
<li>@Html.ActionLink("Additional Parameters", "Parameters", "Example")</li>
@@ -42,6 +43,7 @@
4243
</div>
4344
</div>
4445
</div>
46+
@Scripts.Render("~/bundles/jquery")
4547
@RenderSection("header", false)
4648
<div class="container body-content">
4749
@RenderBody()
@@ -67,7 +69,6 @@
6769
</footer>
6870
</div>
6971

70-
@Scripts.Render("~/bundles/jquery")
7172
@Scripts.Render("~/bundles/bootstrap")
7273
<script src="https://cdnjs.cloudflare.com/ajax/libs/floatthead/1.2.10/jquery.floatThead.min.js"></script>
7374
@Scripts.Render("~/scripts/griddly.js")

0 commit comments

Comments
 (0)