Skip to content

Commit 6027497

Browse files
committed
Fix html filter display rendering and state loading
1 parent e40ff20 commit 6027497

File tree

9 files changed

+42
-12
lines changed

9 files changed

+42
-12
lines changed

Build/CommonAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
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("3.2.21")]
19-
[assembly: AssemblyFileVersion("3.2.21")]
18+
[assembly: AssemblyVersion("3.3.0")]
19+
[assembly: AssemblyFileVersion("3.3.0")]
2020
//[assembly: AssemblyInformationalVersion("2.5-filters")]

Build/Griddly.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<projectUrl>http://griddly.com</projectUrl>
1010
<iconUrl>https://raw.githubusercontent.com/programcsharp/griddly/master/Griddly/Content/griddly-32.png</iconUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12-
<license type="expression">MIT</license>
12+
<!--<license type="expression">MIT</license>-->
1313
<description>Pagable, sortable, MVC enabled grid</description>
1414
<!--<summary></summary>-->
1515
<language>en-US</language>

Griddly.Mvc/GriddlyHtmlFilter.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ namespace Griddly.Mvc
44
{
55
public class GriddlyHtmlFilter : GriddlyFilter
66
{
7-
public Func<GriddlyFilter, object> HtmlTemplate { get; set; }
7+
/// <summary>
8+
/// An Html Template function accepting a GriddlyHtmlFilterModel, and returning an object.
9+
/// </summary>
10+
public Func<GriddlyHtmlFilterModel, object> HtmlTemplate { get; set; }
11+
}
12+
13+
public class GriddlyHtmlFilterModel
14+
{
15+
public GriddlyHtmlFilterModel(GriddlyHtmlFilter filter, object defaultValue)
16+
{
17+
this.Filter = filter;
18+
this.DefaultValue = defaultValue;
19+
}
20+
21+
public GriddlyHtmlFilter Filter { get; protected set; }
22+
23+
public object DefaultValue { get; protected set; }
824
}
925
}

Griddly/Controllers/Examples/FiltersGrid.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ namespace Griddly.Controllers
99
{
1010
public partial class ExampleController : Controller
1111
{
12-
public GriddlyResult FiltersGrid(string[] item, string lastName, string[] state, int? quantityFrom, int? quantityTo, DateTime? dateFrom, DateTime? dateTo, bool? isApproved, bool? totalPositive)
12+
public GriddlyResult FiltersGrid(string[] item, string firstName, string lastName, string[] state, int? quantityFrom, int? quantityTo, DateTime? dateFrom, DateTime? dateTo, bool? isApproved, bool? totalPositive)
1313
{
1414
IQueryable<TestGridItem> query = _testData.AsQueryable();
1515

1616
if (item != null && item.Any())
1717
query = query.Where(x => item.Contains(x.Item));
1818

19+
if (!string.IsNullOrWhiteSpace(firstName))
20+
query = query.Where(x => x.FirstName.IndexOf(firstName, StringComparison.InvariantCultureIgnoreCase) > -1);
21+
1922
if (!string.IsNullOrWhiteSpace(lastName))
2023
query = query.Where(x => x.LastName.IndexOf(lastName, StringComparison.InvariantCultureIgnoreCase) > -1);
2124

Griddly/Scripts/griddly.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@
382382
}, this));
383383

384384
// clear any none's that were inadvertently reset
385-
if (resetContext)
385+
if (resetContext && !isPatch)
386386
{
387387
resetContext
388388
.find("[data-griddly-filter-isnoneall=true] [multiple] option[value='']")
@@ -424,7 +424,7 @@
424424
{
425425
display = filter.data("filter-name");
426426

427-
if (filter.hasClass("griddly-filter-box"))
427+
if (filter.hasClass("griddly-filter-box") || filter.hasClass("griddly-html-filter"))
428428
{
429429
if (dataType == "String")
430430
display += ': "' + getFormattedValue(val, dataType, currencySymbol) + '"';

Griddly/Views/Example/FiltersGrid.cshtml

+13-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
{
3232
PageSize = 20,
3333
RowClickUrl = x => "http://microsoft.com",
34-
EmptyGridMessageTemplate =@<text><div class="alert alert-warning">@item.Settings.EmptyGridMessage</div></text>,
34+
EmptyGridMessageTemplate = @<text><div class="alert alert-warning">@item.Settings.EmptyGridMessage</div></text>,
3535
EmptyGridMessage = "Sorry, no records were found"
3636
};
3737

3838
// Filters on columns
3939
gridSettings
4040
.Column(x => x.Id)
41-
.Column(x => x.Item, filter: x => x.FilterList(groupedList))
41+
.Column(x => x.Item, filter: x => x.FilterList(groupedList, nullItemText: "[Not Set]"))
4242
.Column(x => x.FirstName, "First Name")
4343
.Column(x => x.LastName, "Last Name", filter: x => x.FilterBox(FilterDataType.String))
4444
.Column(x => x.Address)
@@ -57,6 +57,17 @@
5757

5858
// Non-column based filter:
5959
gridSettings.FilterBool("totalPositive", "Total Is Positive", nullItemText: "All");
60+
61+
// Custom HTML filter:
62+
gridSettings.Add(new GriddlyHtmlFilter()
63+
{
64+
Caption = "First Name",
65+
Field = "firstName",
66+
DataType = FilterDataType.String,
67+
HtmlTemplate = @<input class="form-control" name="firstName" type="text" value="@item.Filter.GetFormattedValue(item.DefaultValue)"
68+
placeholder="This is a custom html filter. It can be used for all sorts of things." />
69+
});
70+
6071
}
6172

6273
@Html.Griddly(gridSettings)

Griddly/Views/Shared/Griddly/GriddlyFilterForm.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
}
154154
else if (filterHtml != null)
155155
{
156-
@filterHtml.HtmlTemplate(filter)
156+
@filterHtml.HtmlTemplate(new GriddlyHtmlFilterModel(filterHtml, defaultValue))
157157
}
158158
</div>
159159
</div>

Griddly/Views/Shared/Griddly/GriddlyFilterInline.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
@if (filterHtml != null)
4141
{
42-
@filterHtml.HtmlTemplate(filterHtml)
42+
@filterHtml.HtmlTemplate(new GriddlyHtmlFilterModel(filterHtml, defaultValue))
4343
}
4444
else
4545
{

Griddly/Views/Shared/Griddly/GriddlyFilterValues.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
if (defaultValue != null || defaultValueEnd != null)
2929
{
3030
@FieldValue(filter.Field,
31-
@<text>@filter.Caption@if (filterBox != null)
31+
@<text>@filter.Caption@if (filterBox != null || filterHtml != null)
3232
{
3333
if (filter.DataType == FilterDataType.String)
3434
{<text>: "@filter.GetFormattedValue(defaultValue)"</text>}

0 commit comments

Comments
 (0)