Skip to content

Commit

Permalink
Update package version 4.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rgentry09 committed May 1, 2023
1 parent 422f633 commit 818e6f9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 75 deletions.
159 changes: 85 additions & 74 deletions GridBlazor/CGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,9 @@ private async Task GetOData()
// get count of preprocessed items
string allParameters;
if (string.IsNullOrWhiteSpace(preProcessorParameters))
allParameters = "$count=true&$top=0";
allParameters = "$count=true&$top=0&$skip=0";
else
allParameters = preProcessorParameters + "&$count=true&$top=0";
allParameters = preProcessorParameters + "&$count=true&$top=0&$skip=0";

if (Url.Contains("?"))
allParameters = "&" + allParameters;
Expand Down Expand Up @@ -1486,94 +1486,105 @@ private async Task GetOData()
Items = response.Value;
((GridPager)_pager).ItemsCount = itemsCount;

foreach (IGridColumn<T> column in Columns)
// total back-end queries must not be requested if _query contains a NoTotals parameter with a true value
bool noTotals = false;
if (_query.ContainsKey(GridPager.DefaultNoTotalsParameter))
{
if (column.IsSumEnabled || column.IsAverageEnabled || column.IsMaxEnabled || column.IsMinEnabled)
string noTotalsStr = _query[GridPager.DefaultNoTotalsParameter].FirstOrDefault();
bool.TryParse(noTotalsStr, out noTotals);
}

if (noTotals == false)
{
foreach (IGridColumn<T> column in Columns)
{
bool isNullable = column.Totals.IsNullable();
Type type = column.Totals.GetPropertyType(isNullable);

string filterParameters = GetODataFilterParameters();
if (string.IsNullOrWhiteSpace(filterParameters))
allParameters = "?$apply=";
else
if (column.IsSumEnabled || column.IsAverageEnabled || column.IsMaxEnabled || column.IsMinEnabled)
{
filterParameters = filterParameters.Remove(0, 8);
allParameters = $"?$apply=filter({filterParameters})/";
}
bool isNullable = column.Totals.IsNullable();
Type type = column.Totals.GetPropertyType(isNullable);

var aggregates = new List<string>();
if (column.IsSumEnabled &&
(type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal)))
{
aggregates.Add(column.Totals.GetFullName() + " with sum as Sum");
}
if (column.IsAverageEnabled &&
(type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal)))
{
aggregates.Add(column.Totals.GetFullName() + " with average as Average");
}
if (column.IsMaxEnabled)
{
aggregates.Add(column.Totals.GetFullName() + " with max as Max");
}
if (column.IsMinEnabled)
{
aggregates.Add(column.Totals.GetFullName() + " with min as Min");
}
allParameters += $"aggregate({string.Join(",", aggregates)})";
string filterParameters = GetODataFilterParameters();
if (string.IsNullOrWhiteSpace(filterParameters))
allParameters = "?$apply=";
else
{
filterParameters = filterParameters.Remove(0, 8);
allParameters = $"?$apply=filter({filterParameters})/";
}

var aggregates = new List<string>();
if (column.IsSumEnabled &&
(type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal)))
{
aggregates.Add(column.Totals.GetFullName() + " with sum as Sum");
}
if (column.IsAverageEnabled &&
(type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal)))
{
aggregates.Add(column.Totals.GetFullName() + " with average as Average");
}
if (column.IsMaxEnabled)
{
aggregates.Add(column.Totals.GetFullName() + " with max as Max");
}
if (column.IsMinEnabled)
{
aggregates.Add(column.Totals.GetFullName() + " with min as Min");
}
allParameters += $"aggregate({string.Join(",", aggregates)})";

if (type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal))
{
var totalResponse = await HttpClient.GetFromJsonAsync<List<NumberTotals>>(Url + allParameters, jsonOptions);
if (totalResponse == null || totalResponse.Count > 0)

if (type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal))
{
column.SumValue = new Total(totalResponse.First().Sum);
column.AverageValue = new Total(totalResponse.First().Average);
column.MaxValue = new Total(totalResponse.First().Max);
column.MinValue = new Total(totalResponse.First().Min);
var totalResponse = await HttpClient.GetFromJsonAsync<List<NumberTotals>>(Url + allParameters, jsonOptions);
if (totalResponse == null || totalResponse.Count > 0)
{
column.SumValue = new Total(totalResponse.First().Sum);
column.AverageValue = new Total(totalResponse.First().Average);
column.MaxValue = new Total(totalResponse.First().Max);
column.MinValue = new Total(totalResponse.First().Min);
}
}
}
else if (type == typeof(DateTime))
{
var totalResponse = await HttpClient.GetFromJsonAsync<List<DateTimeTotals>>(Url + allParameters, jsonOptions);
if (totalResponse == null || totalResponse.Count > 0)
else if (type == typeof(DateTime))
{
column.MaxValue = new Total(totalResponse.First().Max);
column.MinValue = new Total(totalResponse.First().Min);
var totalResponse = await HttpClient.GetFromJsonAsync<List<DateTimeTotals>>(Url + allParameters, jsonOptions);
if (totalResponse == null || totalResponse.Count > 0)
{
column.MaxValue = new Total(totalResponse.First().Max);
column.MinValue = new Total(totalResponse.First().Min);
}
}
}
else if (type == typeof(string))
{
var totalResponse = await HttpClient.GetFromJsonAsync<List<StringTotals>>(Url + allParameters, jsonOptions);
if (totalResponse == null || totalResponse.Count > 0)
else if (type == typeof(string))
{
column.MaxValue = new Total(totalResponse.First().Max);
column.MinValue = new Total(totalResponse.First().Min);
var totalResponse = await HttpClient.GetFromJsonAsync<List<StringTotals>>(Url + allParameters, jsonOptions);
if (totalResponse == null || totalResponse.Count > 0)
{
column.MaxValue = new Total(totalResponse.First().Max);
column.MinValue = new Total(totalResponse.First().Min);
}
}
}
}
}
}

foreach (IGridColumn<T> gridColumn in Columns.Where(r => ((IGridColumn<T>)r).Calculations.Any()))
{
foreach (var calculation in gridColumn.Calculations)
foreach (IGridColumn<T> gridColumn in Columns.Where(r => ((IGridColumn<T>)r).Calculations.Any()))
{
var value = calculation.Value(Columns);
Type type = value.GetType();

if (type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal))
foreach (var calculation in gridColumn.Calculations)
{
gridColumn.CalculationValues.AddParameter(calculation.Key, new Total((decimal?)value));
}
else if (type == typeof(DateTime))
{
gridColumn.CalculationValues.AddParameter(calculation.Key, new Total((DateTime)value));
}
else if (type == typeof(string))
{
gridColumn.CalculationValues.AddParameter(calculation.Key, new Total((string)value));
var value = calculation.Value(Columns);
Type type = value.GetType();

if (type == typeof(Single) || type == typeof(Int32) || type == typeof(Int64) || type == typeof(Double) || type == typeof(Decimal))
{
gridColumn.CalculationValues.AddParameter(calculation.Key, new Total((decimal?)value));
}
else if (type == typeof(DateTime))
{
gridColumn.CalculationValues.AddParameter(calculation.Key, new Total((DateTime)value));
}
else if (type == typeof(string))
{
gridColumn.CalculationValues.AddParameter(calculation.Key, new Total((string)value));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>11.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>4.0.2</Version>
<Version>4.0.3</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down

0 comments on commit 818e6f9

Please sign in to comment.