Skip to content

Commit 14fd532

Browse files
committed
Properly update sort field classes in inline filters
Properly update sort field classes on griddly result page refresh
1 parent e9450ac commit 14fd532

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
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.63.0")]
19-
[assembly: AssemblyFileVersion("1.0.63.0")]
18+
[assembly: AssemblyVersion("1.0.64.0")]
19+
[assembly: AssemblyFileVersion("1.0.64.0")]

Griddly.Mvc/GriddlyColumn.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Web;
55
using System.Web.Helpers;
66
using System.Web.WebPages;
7+
using System.Linq;
78

89
namespace Griddly.Mvc
910
{
@@ -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.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/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/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
}

0 commit comments

Comments
 (0)