Skip to content

Commit fbb2622

Browse files
committed
Merge pull request #23 from ithielnor/master
Button selection clearing and filter form rendering
2 parents ca34072 + fdd0c3d commit fbb2622

File tree

11 files changed

+421
-251
lines changed

11 files changed

+421
-251
lines changed

Build/CommonAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Runtime.InteropServices;
33

44
[assembly: AssemblyProduct("Griddly")]
5-
[assembly: AssemblyCopyright("Copyright © 2014 Chris Hynes and Data Research Group")]
5+
[assembly: AssemblyCopyright("Copyright © 2015 Chris Hynes and Data Research Group")]
66

77
[assembly: ComVisible(false)]
88

@@ -15,5 +15,5 @@
1515
//
1616
// You can specify all the values or you can default the Revision and Build Numbers
1717
// by using the '*' as shown below:
18-
[assembly: AssemblyVersion("1.0.80.0")]
19-
[assembly: AssemblyFileVersion("1.0.80.0")]
18+
[assembly: AssemblyVersion("1.0.81.0")]
19+
[assembly: AssemblyFileVersion("1.0.81.0")]

Griddly.Mvc/GriddlyButton.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public GriddlyButton(string additionalClassName = null)
1212

1313
Enabled = true;
1414
Action = GriddlyButtonAction.Navigate;
15+
ClearSelectionOnAction = true;
1516

1617
ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
1718
}
@@ -23,6 +24,12 @@ public GriddlyButton(string additionalClassName = null)
2324
public bool EnableOnSelection { get; set; }
2425
public bool IsSeparator { get; set; }
2526
public bool IsSplitDropdown { get; set; }
27+
28+
/// <summary>
29+
/// Clear the current row selections after this button is activated (default: true)
30+
/// </summary>
31+
public bool ClearSelectionOnAction { get; set; }
32+
2633
public string Text { get; set; }
2734
public string Title { get; set; }
2835
public string Icon { get; set; }

Griddly.Mvc/GriddlySettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class GriddlySettings
3333
/// First argument is the record set. Second argument is the posted form values.
3434
/// </summary>s
3535
public static Func<IEnumerable, NameValueCollection, ActionResult> HandleCustomExport = null;
36-
public static Action<GriddlySettings, ViewContext> BeforeRender = null;
36+
public static Action<GriddlySettings, HtmlHelper> BeforeRender = null;
3737
public static Action<GriddlySettings, ControllerContext> OnGriddlyResultExecuting = null;
3838

3939
public GriddlySettings()

Griddly/Griddly.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@
247247
<Content Include="Views\Home\FilterListGrid.cshtml" />
248248
<Content Include="_AppStart.cshtml" />
249249
<Content Include="Views\Home\IndexGrid.cshtml" />
250+
<Content Include="Views\Shared\Griddly\GriddlyFilterInline.cshtml" />
251+
<Content Include="Views\Shared\Griddly\GriddlyFilterForm.cshtml" />
250252
</ItemGroup>
251253
<ItemGroup>
252254
<ProjectReference Include="..\Griddly.Mvc\Griddly.Mvc.csproj">

Griddly/Scripts/griddly.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,9 @@
186186
this.resetFilterValues();
187187
}, this));
188188

189-
$("a.btn-search", this.$element).on("click", $.proxy(function (event)
189+
$("a.btn-search, button.btn-search", this.$element).on("click", $.proxy(function (event)
190190
{
191-
if (this.options.allowedFilterModes.length > 1)
192-
{
193-
this.options.filterMode = this.options.filterMode == "Inline" ? "Form" : "Inline";
194-
195-
this.$element.find("tr.griddly-filters:not(tr.griddly-filters-" + this.options.filterMode.toLowerCase() + ")").hide();
196-
this.$element.find("tr.griddly-filters-" + this.options.filterMode.toLowerCase()).show();
197-
198-
// TODO: only refresh if filter values changed
199-
this.refresh(true);
200-
}
191+
this.toggleFilterMode();
201192
}, this));
202193

203194
$(this.$element).on("mouseup", "tbody.data tr td:not(:has(input))", $.proxy(function (e)
@@ -356,11 +347,12 @@
356347
{
357348
var last = $("tbody tr", this.$element).index(this.options.lastSelectedRow);
358349
var first = $("tbody tr", this.$element).index($target.parents("tr"));
350+
var newstate = this.options.lastSelectedRow.find("input[name=_rowselect]").prop("checked");
359351

360352
var start = Math.min(first, last);
361353
var end = Math.max(first, last);
362354

363-
$("tbody tr", this.$element).slice(start, end).find("input[name=_rowselect]").prop("checked", true);
355+
$("tbody tr", this.$element).slice(start, end).find("input[name=_rowselect]").each(function () { $(this).prop("checked", newstate); setRowSelect($(this)) });
364356
}
365357

366358
this.options.lastSelectedRow = $target.parents("tr");
@@ -378,12 +370,8 @@
378370

379371
$(this.$element).on("click", "thead tr .griddly-selection-clear", $.proxy(function (event)
380372
{
381-
this.options.selectedRows = {};
382-
383-
$("tbody tr", this.$element).find("input[name=_rowselect]").prop("checked", false);
384-
373+
this.clearSelected();
385374
onRowChange();
386-
this.setSelectedCount();
387375
}, this));
388376

389377
$("a.export-xlsx", this.$element).on("click", $.proxy(function (e) {
@@ -705,6 +693,20 @@
705693
}
706694
},
707695

696+
toggleFilterMode: function()
697+
{
698+
if (this.options.allowedFilterModes.length > 1)
699+
{
700+
this.options.filterMode = this.options.filterMode == "Inline" ? "Form" : "Inline";
701+
702+
this.$element.find("tr.griddly-filters:not(tr.griddly-filters-" + this.options.filterMode.toLowerCase() + ")").hide();
703+
this.$element.find("tr.griddly-filters-" + this.options.filterMode.toLowerCase()).show();
704+
705+
// TODO: only refresh if filter values changed
706+
this.refresh(true);
707+
}
708+
},
709+
708710
getFilterValues: function()
709711
{
710712
var allFilters;
@@ -893,6 +895,15 @@
893895
return result;
894896
},
895897

898+
clearSelected: function()
899+
{
900+
this.options.selectedRows = {};
901+
902+
$("tbody tr", this.$element).find("input[name=_rowselect]").prop("checked", false);
903+
904+
this.setSelectedCount();
905+
},
906+
896907
pageNumber: function(pageNumber)
897908
{
898909
if (pageNumber >= 0 && pageNumber < this.options.pageCount)
@@ -970,6 +981,7 @@
970981
var onclick = button.data("onclick");
971982
var confirmMessage = button.data("confirm-message");
972983
var enableOnSelection = button.data("enable-on-selection");
984+
var clearSelectionOnAction = button.data("clear-selection-on-action");
973985
var rowIds = button.data("rowids");
974986

975987
if ((typeof confirmMessage === "undefined" || confirm(confirmMessage)))
@@ -993,6 +1005,11 @@
9931005
}
9941006
}
9951007

1008+
if (clearSelectionOnAction && griddly.length)
1009+
{
1010+
griddly.griddly("clearSelected");
1011+
}
1012+
9961013
switch (toggle)
9971014
{
9981015
case "ajaxbulk":
@@ -1027,7 +1044,14 @@
10271044

10281045
if ($.isFunction(f))
10291046
{
1030-
return f.call(button, rowIds);
1047+
var result = f.call(button, rowIds);
1048+
1049+
if (clearSelectionOnAction && griddly.length)
1050+
{
1051+
griddly.griddly("clearSelected");
1052+
}
1053+
1054+
return result;
10311055
}
10321056

10331057
throw "onclick must be a global function";
@@ -1096,7 +1120,7 @@
10961120
.appendTo("body").submit().remove();
10971121
};
10981122

1099-
GriddlyButton.ajax = function (url, selection, button, griddly)
1123+
GriddlyButton.ajax = function (url, selection, button, griddly, clearSelection)
11001124
{
11011125
for (var i = 0; i < selection[Object.keys(selection)[0]].length; i++)
11021126
{
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11

22
@{
33
ViewBag.Title = "TestGrid";
4+
5+
var enumList = typeof(FilterDataType).GetEnumValues().Cast<FilterDataType>().Select(y => new SelectListItem() { Value = ((int)y).ToString(), Text = y.ToString() });
46
}
57

68
@Html.Griddly(new GriddlySettings<TestGridItem>()
7-
{
9+
{
810
PageSize = 5,
9-
ClassName = "filter-range-grid"
11+
ClassName = "filter-range-grid",
12+
AllowedFilterModes = FilterMode.Both
1013
}
1114
.Column(x => x.FirstName, "First Name", defaultSort: SortDirection.Ascending)
12-
.Column(x => x.LastName, "Last Name")
13-
.Column(x => x.Company, "Company", filter: x => x.FilterRange(FilterDataType.Decimal))
14-
.Column(x => x.Address, "Address", filter: x => x.FilterRange(FilterDataType.Currency))
15-
.Column(x => x.State, "State", filter: x => x.FilterRange(FilterDataType.Date))
16-
.Column(x => x.PostalCode, "Zip", filter: x => x.FilterRange(FilterDataType.Integer))
15+
.Column(x => x.LastName, "Last Name")
16+
.Column(x => x.Company, "Company", filter: x => x.FilterList(enumList, defaultSelectAll: true))
17+
.Column(x => x.Address, "Address", filter: x => x.FilterRange(FilterDataType.Integer))
18+
.Column(x => x.State, "State", filter: x => x.FilterRange(FilterDataType.Date))
19+
.Column(x => x.PostalCode, "Zip", filter: x => x.FilterBool(nullItemText: "Both"))
20+
.Add(new GriddlyButton("btn-search") { Text = "Show Filter Form" })
1721
)

Griddly/Views/Shared/Griddly/BootstrapButton.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@*
22
* GriddlyButton renderer using Bootstrap html and styles
33
* http://griddly.com
4-
* Copyright 2013-2014 Chris Hynes and Data Research Group, Inc.
4+
* Copyright 2013-2015 Chris Hynes and Data Research Group, Inc.
55
* Licensed under MIT (https://github.com/programcsharp/griddly/blob/master/LICENSE)
66
*
77
* WARNING: Don't edit this file -- it'll be overwitten when you upgrade.
@@ -77,6 +77,7 @@ else
7777
@Html.AttributeIf("data-url", button.Action == GriddlyButtonAction.Ajax || button.Action == GriddlyButtonAction.AjaxBulk || button.Action == GriddlyButtonAction.Post || button.Action == GriddlyButtonAction.PostCriteria, button.Argument)
7878
@Html.AttributeIf("data-target", button.Action != GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
7979
@Html.AttributeIf("data-enable-on-selection", button.EnableOnSelection, button.EnableOnSelection.ToString().ToLower())
80+
@Html.AttributeIf("data-clear-selection-on-action", button.ClearSelectionOnAction, button.ClearSelectionOnAction.ToString().ToLower())
8081
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
8182
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
8283
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")

Griddly/Views/Shared/Griddly/ButtonStrip.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@*
22
* GriddlyButton button strip renderer using Bootstrap html and styles
33
* http://griddly.com
4-
* Copyright 2013-2014 Chris Hynes and Data Research Group, Inc.
4+
* Copyright 2013-2015 Chris Hynes and Data Research Group, Inc.
55
* Licensed under MIT (https://github.com/programcsharp/griddly/blob/master/LICENSE)
66
*
77
* WARNING: Don't edit this file -- it'll be overwitten when you upgrade.

0 commit comments

Comments
 (0)