Skip to content

Commit c8dd5b3

Browse files
Remove empty Group.summary from response
1 parent 2a8c46e commit c8dd5b3

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

net/DevExtreme.AspNet.Data.Tests/DataSourceLoaderTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,36 @@ public void Load_SummaryAndIsExpandedFalse() {
203203
Assert.Equal(2, groups[0].count);
204204
}
205205

206+
[Theory]
207+
[InlineData(false)]
208+
[InlineData(true)]
209+
public void Load_EmptySummary(bool remoteGrouping) {
210+
var data = new[] {
211+
new { g = 1 }
212+
};
213+
214+
var loadOptions = new SampleLoadOptions {
215+
RemoteGrouping = remoteGrouping,
216+
Group = new[] {
217+
new GroupingInfo { Selector = "g", IsExpanded = false }
218+
}
219+
};
220+
221+
void Run() {
222+
var loadResult = DataSourceLoader.Load(data, loadOptions);
223+
Assert.Null(loadResult.summary);
224+
Assert.Null(loadResult.data.Cast<Group>().First().summary);
225+
}
226+
227+
Assert.Null(loadOptions.TotalSummary);
228+
Assert.Null(loadOptions.GroupSummary);
229+
Run();
230+
231+
loadOptions.TotalSummary = Array.Empty<SummaryInfo>();
232+
loadOptions.GroupSummary = Array.Empty<SummaryInfo>();
233+
Run();
234+
}
235+
206236
[Fact]
207237
public void RequireGroupCountWhenGroupsAreExpanded() {
208238
var data = new[] {

net/DevExtreme.AspNet.Data/Aggregation/AggregateCalculator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ class AggregateCalculator<T> {
2323
public AggregateCalculator(IEnumerable data, IAccessor<T> accessor, IList<SummaryInfo> totalSummary, IList<SummaryInfo> groupSummary, SumFix sumFix = null) {
2424
_data = data;
2525
_accessor = accessor;
26-
_totalSummary = totalSummary;
27-
_groupSummary = groupSummary;
2826
_sumFix = sumFix ?? new SumFix(typeof(T), totalSummary, groupSummary);
2927

30-
_totalAggregators = _totalSummary?.Select(CreateAggregator).ToArray();
28+
if(totalSummary != null && totalSummary.Count > 0)
29+
_totalAggregators = totalSummary.Select(CreateAggregator).ToArray();
3130

32-
if(groupSummary != null)
31+
if(groupSummary != null && groupSummary.Count > 0)
3332
_groupAggregatorsStack = new Stack<Aggregator<T>[]>();
33+
34+
_totalSummary = totalSummary;
35+
_groupSummary = groupSummary;
3436
}
3537

3638
public object[] Run() {

net/DevExtreme.AspNet.Data/RemoteGrouping/RemoteGroupTransformer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static RemoteGroupingResult Run(Type sourceItemType, IEnumerable<AnonType
2929
var transformedTotalSummary = TransformSummary(totalSummary, ref fieldIndex);
3030
var transformedGroupSummary = TransformSummary(groupSummary, ref fieldIndex);
3131

32+
transformedTotalSummary = transformedTotalSummary ?? new List<SummaryInfo>();
3233
transformedTotalSummary.Add(new SummaryInfo { SummaryType = AggregateName.REMOTE_COUNT });
3334

3435
var sumFix = new SumFix(sourceItemType, totalSummary, groupSummary);
@@ -47,9 +48,10 @@ public static RemoteGroupingResult Run(Type sourceItemType, IEnumerable<AnonType
4748
}
4849

4950
static List<SummaryInfo> TransformSummary(SummaryInfo[] original, ref int fieldIndex) {
50-
var result = new List<SummaryInfo>();
5151
if(original == null)
52-
return result;
52+
return null;
53+
54+
var result = new List<SummaryInfo>();
5355

5456
for(var originalIndex = 0; originalIndex < original.Length; originalIndex++) {
5557
var originalType = original[originalIndex].SummaryType;

0 commit comments

Comments
 (0)