Skip to content

Commit fdc1413

Browse files
committed
Render filter settings for filter form items
Render optgroups for SelectListItemGroup in filter form lists Bool filter values should match stuff that will work in js
1 parent d918b37 commit fdc1413

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
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("1.6.5")]
19-
[assembly: AssemblyFileVersion("1.6.5")]
18+
[assembly: AssemblyVersion("1.6.6")]
19+
[assembly: AssemblyFileVersion("1.6.6")]
2020
//[assembly: AssemblyInformationalVersion("1.4.5-editlyalpha2")]

Griddly.Mvc/GriddlyFilterExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static List<SelectListItem> BuildBoolItems(string trueLabel, string falseLabel)
149149
{
150150
return new List<SelectListItem>()
151151
{
152-
new SelectListItem() { Value = "True", Text = trueLabel },
153-
new SelectListItem() { Value = "False", Text = falseLabel },
152+
new SelectListItem() { Value = "true", Text = trueLabel },
153+
new SelectListItem() { Value = "false", Text = falseLabel },
154154
};
155155
}
156156
}

Griddly/Scripts/griddly.js

+3
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@
988988

989989
this.setFilterValues(this.options.filterDefaults);
990990

991+
// clear any none's that were inadvertently reset
992+
this.$element.find(".griddly-filters-form [data-griddly-filter-isnoneall=true] [multiple] option[value=]").prop("selected", false);
993+
991994
this.triggerOrQueue(this.$element, "resetfilters.griddly");
992995

993996
this.refresh(true);

Griddly/Views/Shared/Griddly/GriddlyFilterForm.cshtml

+28-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
object defaultValue = this.GetGriddlyDefault(filter.Field);
2222
object defaultValueEnd = filterRange != null ? this.GetGriddlyDefault(filterRange.FieldEnd) : null;
2323

24-
<div class="griddly-filter-form-group form-group form-group-sm">
24+
<div class="griddly-filter-form-group form-group form-group-sm"
25+
data-filter-name="@filter.Caption" data-filter-name-plural="@filter.CaptionPlural"
26+
data-filter-datatype="@filter.DataType.ToString()"
27+
@Html.AttributeIf("data-griddly-filter-ismultiple", filterList != null, x => filterList.IsMultiple.ToString().ToLower())
28+
@Html.AttributeIf("data-griddly-filter-isnoneall", filterList != null, x => filterList.IsNoneAll.ToString().ToLower())
29+
@Html.AttributeIf("data-griddly-filter-isnullable", filterList != null, x => filterList.IsNullable.ToString().ToLower())
30+
@Html.AttributeIf("data-griddly-filter-displayitemcount", filterList != null, x => filterList.DisplayItemCount)>
2531
<label for="[email protected]" class="col-sm-2 control-label">@filter.Caption</label>
2632
@if (filterBox != null)
2733
{
@@ -107,11 +113,24 @@
107113
filterList.SetSelectedItems(defaultValue);
108114

109115
<div class="col-sm-3">
110-
<select class="form-control col-sm-3" id="[email protected]" name="@filter.Field" @(filterList.IsMultiple ? "multiple" : null)
111-
data-griddly-filter-data-type="@filter.DataType">
116+
<select class="form-control col-sm-3" id="[email protected]" name="@filter.Field" @(filterList.IsMultiple ? "multiple" : null)>
112117
@foreach (SelectListItem item in filterList.Items)
113118
{
114-
<option value="@item.Value" @(item.Selected ? "selected" : null)>@item.Text</option>
119+
SelectListItemGroup group = item as SelectListItemGroup;
120+
121+
if (group != null)
122+
{
123+
<optgroup label="@group.Text">
124+
@foreach (SelectListItem childItem in group.Items)
125+
{
126+
@RenderListItem(childItem)
127+
}
128+
</optgroup>
129+
}
130+
else
131+
{
132+
@RenderListItem(item)
133+
}
115134
}
116135
</select>
117136
</div>
@@ -123,4 +142,9 @@
123142
</div>
124143
}
125144
</div>
145+
}
146+
147+
@helper RenderListItem(SelectListItem item)
148+
{
149+
<option value="@item.Value" @(item.Selected ? "selected" : null)>@item.Text</option>
126150
}

0 commit comments

Comments
 (0)