Skip to content

Commit 6531bb2

Browse files
committed
2 parents d96c873 + 8520b29 commit 6531bb2

File tree

10 files changed

+82
-27
lines changed

10 files changed

+82
-27
lines changed

Build/CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.60.0")]
19-
[assembly: AssemblyFileVersion("1.0.70.0")]
18+
[assembly: AssemblyVersion("1.0.65.0")]
19+
[assembly: AssemblyFileVersion("1.0.65.0")]

Griddly.Mvc/Griddly.Mvc.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@
115115
</ItemGroup>
116116
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
117117
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
118-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
119-
<PropertyGroup>
120-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
121-
</PropertyGroup>
122-
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
123-
</Target>
124118
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
125119
Other similar extension points exist, see Microsoft.Common.targets.
126120
<Target Name="BeforeBuild">

Griddly.Mvc/GriddlyColumn.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45
using System.Web;
56
using System.Web.Helpers;
@@ -21,7 +22,7 @@ public abstract class GriddlyColumn
2122

2223
public abstract HtmlString RenderCell(object row, bool encode = true);
2324
public abstract object RenderCellValue(object row, bool stripHtml = false);
24-
public abstract string RenderClassName(object row);
25+
public abstract string RenderClassName(object row, GriddlyResultPage page);
2526

2627
protected virtual HtmlString RenderValue(object value, bool encode = true)
2728
{
@@ -57,15 +58,17 @@ public class GriddlyColumn<TRow> : GriddlyColumn
5758

5859
static readonly Regex _htmlMatch = new Regex(@"<[^>]*>", RegexOptions.Compiled);
5960

60-
public override string RenderClassName(object row)
61+
public override string RenderClassName(object row, GriddlyResultPage page)
6162
{
6263
HashSet<string> classes = new HashSet<string>();
6364

6465
if (!string.IsNullOrWhiteSpace(ClassName))
6566
classes.UnionWith(ClassName.Split(' '));
6667

67-
if (DefaultSort != null)
68-
classes.Add("sorted_" + (DefaultSort == SortDirection.Descending ? "d" : "a"));
68+
SortField field = !string.IsNullOrWhiteSpace(SortField) && page.SortFields != null ? page.SortFields.FirstOrDefault(x => x.Field == SortField) : null;
69+
70+
if (field != null)
71+
classes.Add("sorted_" + (field.Direction == SortDirection.Descending ? "d" : "a"));
6972

7073
if (ClassNameExpression != null)
7174
{

Griddly.Mvc/GriddlyFilter.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using System.Collections.Generic;
44
using System.Data.Entity.Design.PluralizationServices;
55
using System.Globalization;
6-
using System.Web.Mvc;
76
using System.Linq;
7+
using System.Web.Mvc;
88

99
namespace Griddly.Mvc
1010
{
@@ -117,7 +117,7 @@ public void SetSelectedItems(object value)
117117

118118
if (defaultValues == null || value is string)
119119
{
120-
string valueString = value.ToString();
120+
string valueString = value.ToString();// GetValueString(value);
121121

122122
foreach (SelectListItem item in SelectableItems)
123123
item.Selected = item.Value == valueString;
@@ -126,10 +126,18 @@ public void SetSelectedItems(object value)
126126
{
127127
foreach (object valueObject in defaultValues)
128128
{
129-
string valueString = valueObject.ToString();
130-
131-
foreach (SelectListItem item in SelectableItems.Where(x => x.Value == valueString))
132-
item.Selected = true;
129+
if (valueObject != null)
130+
{
131+
string valueString = valueObject.ToString();// GetValueString(valueObject);
132+
133+
foreach (SelectListItem item in SelectableItems.Where(x => x.Value == valueString))
134+
item.Selected = true;
135+
}
136+
else
137+
{
138+
foreach (SelectListItem item in SelectableItems.Where(x => string.IsNullOrWhiteSpace(x.Value)))
139+
item.Selected = true;
140+
}
133141
}
134142
}
135143
}
@@ -140,8 +148,17 @@ public void SetSelectedItems(object value)
140148
Items[i].Selected = (i == 0);
141149
}
142150
}
143-
144151
}
152+
153+
//string GetValueString(object value)
154+
//{
155+
// Type valueType = Nullable.GetUnderlyingType(value.GetType()) ?? value.GetType();
156+
157+
// if (valueType.IsEnum)
158+
// return Convert.ChangeType(value, Enum.GetUnderlyingType(valueType)).ToString();
159+
// else
160+
// return value.ToString();
161+
//}
145162
}
146163

147164
public enum FilterDataType

Griddly.Mvc/GriddlyFilterExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public static GriddlyFilterList FilterEnum<T>(this GriddlyColumn column, bool is
114114
return column.FilterList(Extensions.ToSelectListItems<T>().OrderBy(x => x.Text), isMultiple, defaultSelectAll, nullItemText, isNoneAll, field, caption);
115115
}
116116

117+
public static GriddlyFilterList FilterEnum<T>(this GriddlyColumn column, IEnumerable<T> items, bool isMultiple = true, bool defaultSelectAll = true, string nullItemText = null, bool isNoneAll = true, string field = null, string caption = null)
118+
where T : struct
119+
{
120+
return column.FilterList(Extensions.ToSelectListItems(items).OrderBy(x => x.Text), isMultiple, defaultSelectAll, nullItemText, isNoneAll, field, caption);
121+
}
122+
117123
public static GriddlyFilterList FilterBool(this GriddlyColumn column, string trueLabel = "Yes", string falseLabel = "No", string nullItemText = null, bool isMultiple = false, bool defaultSelectAll = false, bool isNoneAll = false, string field = null, string caption = null)
118124
{
119125
return column.FilterList(BuildBoolItems(trueLabel, falseLabel), isMultiple, defaultSelectAll, nullItemText, isNoneAll, field, caption);

Griddly.Mvc/GriddlySelectColumn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override object RenderCellValue(object row, bool stripHtml = false)
2929
return null;
3030
}
3131

32-
public override string RenderClassName(object row)
32+
public override string RenderClassName(object row, GriddlyResultPage page)
3333
{
3434
return null;
3535
}

Griddly.Mvc/InternalExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ internal static IEnumerable<SelectListItem> ToSelectListItems<T>()
109109
}
110110
}
111111

112+
internal static IEnumerable<SelectListItem> ToSelectListItems<T>(IEnumerable<T> items)
113+
where T : struct
114+
{
115+
Type enumType = typeof(T);
116+
117+
if (!enumType.IsEnum)
118+
throw new InvalidOperationException("T must be an Enum.");
119+
120+
foreach (T item in items)
121+
{
122+
FieldInfo field = enumType.GetField(item.ToString());
123+
124+
yield return new SelectListItem()
125+
{
126+
Value = field.GetValue(null).ToString(),
127+
Text = GetEnumDescription(field)
128+
};
129+
}
130+
}
131+
112132
static string GetEnumDescription(FieldInfo fi)
113133
{
114134
if (fi == null)

Griddly/Scripts/griddly.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,23 @@
219219
var currentDirection = currentPos != -1 ? this.options.sortFields[currentPos].Direction : "Descending";
220220
var newDirection = currentDirection == "Descending" ? "Ascending" : "Descending";
221221

222+
var inlineFilters = $("tr.griddly-filters-inline", this.element);
223+
222224
if (!this.options.isMultiSort || !event.ctrlKey)
223225
{
224226
for (var i = 0; i < this.options.sortFields.length; i++)
225227
{
226228
var thisSortField = this.options.sortFields[i].Field;
227229

228230
if (thisSortField != sortField)
229-
$(event.currentTarget).parents("tr").find("th[data-griddly-sortfield='" + thisSortField + "']").removeClass("sorted_a").removeClass("sorted_d");
231+
{
232+
var oldSortDisplay = $(event.currentTarget).parents("tr").find("th[data-griddly-sortfield='" + thisSortField + "']");
233+
234+
if (inlineFilters.length)
235+
oldSortDisplay = [oldSortDisplay[0], inlineFilters[0].cells[oldSortDisplay[0].cellIndex]];
236+
237+
$(oldSortDisplay).removeClass("sorted_a").removeClass("sorted_d");
238+
}
230239
}
231240

232241
this.options.sortFields = [];
@@ -237,11 +246,17 @@
237246
else
238247
this.options.sortFields.push({ Field: sortField, Direction: newDirection });
239248

249+
250+
var newSortDisplay = [event.currentTarget];
251+
252+
if (inlineFilters.length)
253+
newSortDisplay.push(inlineFilters[0].cells[newSortDisplay[0].cellIndex]);
254+
240255
if (newDirection == "Ascending")
241-
$(event.currentTarget).removeClass("sorted_d").addClass("sorted_a");
256+
$(newSortDisplay).removeClass("sorted_d").addClass("sorted_a");
242257
else
243-
$(event.currentTarget).removeClass("sorted_a").addClass("sorted_d");
244-
258+
$(newSortDisplay).removeClass("sorted_a").addClass("sorted_d");
259+
245260
this.refresh(true);
246261
}
247262
}, this));

Griddly/Views/Shared/Griddly/Griddly.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
@Html.AttributeNullable("data-id", TryEval(row, settings.IdProperty))>
127127
@foreach (GriddlyColumn column in settings.Columns)
128128
{
129-
<td class="@column.RenderClassName(row)">@column.RenderCell(row)</td>
129+
<td class="@column.RenderClassName(row, Model)">@column.RenderCell(row)</td>
130130
}
131131
</tr>
132132
}

Griddly/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>@ViewBag.Title - My ASP.NET Application</title>
6+
<title>@ViewBag.Title - Griddly Test</title>
77
@Styles.Render("~/Content/css")
88
@Scripts.Render("~/bundles/modernizr")
99
</head>
@@ -16,7 +16,7 @@
1616
<span class="icon-bar"></span>
1717
<span class="icon-bar"></span>
1818
</button>
19-
@Html.ActionLink("Application name", "Index", "Home", null, new { @class = "navbar-brand" })
19+
@Html.ActionLink("Griddly Test", "Index", "Home", null, new { @class = "navbar-brand" })
2020
</div>
2121
<div class="navbar-collapse collapse">
2222
<ul class="nav navbar-nav">

0 commit comments

Comments
 (0)