Skip to content

Commit fdd0c3d

Browse files
committed
Customizable filter form support.
1 parent 6f6697c commit fdd0c3d

File tree

10 files changed

+388
-245
lines changed

10 files changed

+388
-245
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/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: 18 additions & 13 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)
@@ -702,6 +693,20 @@
702693
}
703694
},
704695

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+
705710
getFilterValues: function()
706711
{
707712
var allFilters;
@@ -1000,7 +1005,7 @@
10001005
}
10011006
}
10021007

1003-
if (clearSelectionOnAction)
1008+
if (clearSelectionOnAction && griddly.length)
10041009
{
10051010
griddly.griddly("clearSelected");
10061011
}
@@ -1041,7 +1046,7 @@
10411046
{
10421047
var result = f.call(button, rowIds);
10431048

1044-
if (clearSelectionOnAction)
1049+
if (clearSelectionOnAction && griddly.length)
10451050
{
10461051
griddly.griddly("clearSelected");
10471052
}
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: 1 addition & 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.

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)