Skip to content

Commit 8e053ff

Browse files
committed
GetAllForProperty returns sorted results
1 parent 429fde6 commit 8e053ff

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

Griddly.Mvc/GriddlyResult.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public SortField[] GetSortFields(NameValueCollection items)
4646

4747
public abstract long GetCount();
4848

49-
public abstract IEnumerable<P> GetAllForProperty<P>(string propertyName);
49+
public abstract IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields);
5050
}
5151

5252
public abstract class GriddlyResult<T> : GriddlyResult
@@ -180,7 +180,7 @@ public override void ExecuteResult(ControllerContext context)
180180

181181
public abstract void PopulateSummaryValues(GriddlySettings<T> settings);
182182

183-
public override IEnumerable<P> GetAllForProperty<P>(string propertyName)
183+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
184184
{
185185
throw new NotImplementedException();
186186
}

Griddly.Mvc/Results/DapperResult.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public override void PopulateSummaryValues(GriddlySettings<T> settings)
7979
}
8080
}
8181

82-
public override IEnumerable<P> GetAllForProperty<P>(string propertyName)
82+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
8383
{
8484
if (propertyName.Contains("."))
8585
throw new ArgumentException($"Property name may not contain a period. \"{propertyName}\"", "propertyName");
8686

87-
string sql = string.Format("SELECT {0} as _val FROM ({1}) [_proj]", propertyName, _sql);
87+
string sql = $"SELECT {propertyName} as _val FROM ({_sql}) [_proj] {(_fixedSort ? "" : $"ORDER BY {BuildSortClause(sortFields) ?? "CURRENT_TIMESTAMP"}")}";
8888

8989
try
9090
{

Griddly.Mvc/Results/MapQueryableResult.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public override void PopulateSummaryValues(GriddlySettings<TOut> settings)
4040
_result.PopulateSummaryValue(c);
4141
}
4242

43-
public override IEnumerable<P> GetAllForProperty<P>(string propertyName)
43+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
4444
{
45-
return _result.GetAllForProperty<P>(propertyName);
45+
return _result.GetAllForProperty<P>(propertyName, sortFields);
4646
}
4747

4848
public override long GetCount()

Griddly.Mvc/Results/QueryableResult.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ internal void PopulateSummaryValue(GriddlyColumn c)
9393
}
9494
}
9595

96-
public override IEnumerable<P> GetAllForProperty<P>(string propertyName)
96+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
9797
{
98-
return _result.Select<P>(propertyName, null);
98+
return ApplySortFields(_result, sortFields)
99+
.Select<P>(propertyName, null);
99100
}
100101

101102
public override long GetCount()

Griddly/Controllers/HomeController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static ActionResult HandleCustomExport(GriddlyResult result, NameValueCol
1616
{
1717
return new JsonResult()
1818
{
19-
Data = result.GetAllForProperty<long?>("Id"),
19+
Data = result.GetAllForProperty<long?>("Id", null),
2020
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
2121
};
2222
}

0 commit comments

Comments
 (0)