Skip to content

Commit

Permalink
Fix html filter display rendering and state loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ithielnor committed May 14, 2020
1 parent e40ff20 commit 6027497
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.2.21")]
[assembly: AssemblyFileVersion("3.2.21")]
[assembly: AssemblyVersion("3.3.0")]
[assembly: AssemblyFileVersion("3.3.0")]
//[assembly: AssemblyInformationalVersion("2.5-filters")]
2 changes: 1 addition & 1 deletion Build/Griddly.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<projectUrl>http://griddly.com</projectUrl>
<iconUrl>https://raw.githubusercontent.com/programcsharp/griddly/master/Griddly/Content/griddly-32.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<!--<license type="expression">MIT</license>-->
<description>Pagable, sortable, MVC enabled grid</description>
<!--<summary></summary>-->
<language>en-US</language>
Expand Down
18 changes: 17 additions & 1 deletion Griddly.Mvc/GriddlyHtmlFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ namespace Griddly.Mvc
{
public class GriddlyHtmlFilter : GriddlyFilter
{
public Func<GriddlyFilter, object> HtmlTemplate { get; set; }
/// <summary>
/// An Html Template function accepting a GriddlyHtmlFilterModel, and returning an object.
/// </summary>
public Func<GriddlyHtmlFilterModel, object> HtmlTemplate { get; set; }
}

public class GriddlyHtmlFilterModel
{
public GriddlyHtmlFilterModel(GriddlyHtmlFilter filter, object defaultValue)
{
this.Filter = filter;
this.DefaultValue = defaultValue;
}

public GriddlyHtmlFilter Filter { get; protected set; }

public object DefaultValue { get; protected set; }
}
}
5 changes: 4 additions & 1 deletion Griddly/Controllers/Examples/FiltersGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ namespace Griddly.Controllers
{
public partial class ExampleController : Controller
{
public GriddlyResult FiltersGrid(string[] item, string lastName, string[] state, int? quantityFrom, int? quantityTo, DateTime? dateFrom, DateTime? dateTo, bool? isApproved, bool? totalPositive)
public GriddlyResult FiltersGrid(string[] item, string firstName, string lastName, string[] state, int? quantityFrom, int? quantityTo, DateTime? dateFrom, DateTime? dateTo, bool? isApproved, bool? totalPositive)
{
IQueryable<TestGridItem> query = _testData.AsQueryable();

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

if (!string.IsNullOrWhiteSpace(firstName))
query = query.Where(x => x.FirstName.IndexOf(firstName, StringComparison.InvariantCultureIgnoreCase) > -1);

if (!string.IsNullOrWhiteSpace(lastName))
query = query.Where(x => x.LastName.IndexOf(lastName, StringComparison.InvariantCultureIgnoreCase) > -1);

Expand Down
4 changes: 2 additions & 2 deletions Griddly/Scripts/griddly.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
}, this));

// clear any none's that were inadvertently reset
if (resetContext)
if (resetContext && !isPatch)
{
resetContext
.find("[data-griddly-filter-isnoneall=true] [multiple] option[value='']")
Expand Down Expand Up @@ -424,7 +424,7 @@
{
display = filter.data("filter-name");

if (filter.hasClass("griddly-filter-box"))
if (filter.hasClass("griddly-filter-box") || filter.hasClass("griddly-html-filter"))
{
if (dataType == "String")
display += ': "' + getFormattedValue(val, dataType, currencySymbol) + '"';
Expand Down
15 changes: 13 additions & 2 deletions Griddly/Views/Example/FiltersGrid.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
{
PageSize = 20,
RowClickUrl = x => "http://microsoft.com",
EmptyGridMessageTemplate =@<text><div class="alert alert-warning">@item.Settings.EmptyGridMessage</div></text>,
EmptyGridMessageTemplate = @<text><div class="alert alert-warning">@item.Settings.EmptyGridMessage</div></text>,
EmptyGridMessage = "Sorry, no records were found"
};

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

// Non-column based filter:
gridSettings.FilterBool("totalPositive", "Total Is Positive", nullItemText: "All");

// Custom HTML filter:
gridSettings.Add(new GriddlyHtmlFilter()
{
Caption = "First Name",
Field = "firstName",
DataType = FilterDataType.String,
HtmlTemplate = @<input class="form-control" name="firstName" type="text" value="@item.Filter.GetFormattedValue(item.DefaultValue)"
placeholder="This is a custom html filter. It can be used for all sorts of things." />
});

}

@Html.Griddly(gridSettings)
2 changes: 1 addition & 1 deletion Griddly/Views/Shared/Griddly/GriddlyFilterForm.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
}
else if (filterHtml != null)
{
@filterHtml.HtmlTemplate(filter)
@filterHtml.HtmlTemplate(new GriddlyHtmlFilterModel(filterHtml, defaultValue))
}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Griddly/Views/Shared/Griddly/GriddlyFilterInline.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
@if (filterHtml != null)
{
@filterHtml.HtmlTemplate(filterHtml)
@filterHtml.HtmlTemplate(new GriddlyHtmlFilterModel(filterHtml, defaultValue))
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Griddly/Views/Shared/Griddly/GriddlyFilterValues.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
if (defaultValue != null || defaultValueEnd != null)
{
@FieldValue(filter.Field,
@<text>@filter.Caption@if (filterBox != null)
@<text>@filter.Caption@if (filterBox != null || filterHtml != null)
{
if (filter.DataType == FilterDataType.String)
{<text>: "@filter.GetFormattedValue(defaultValue)"</text>}
Expand Down

0 comments on commit 6027497

Please sign in to comment.