首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用DevExtreme、SummaryType.Custom获取错误

使用DevExtreme、SummaryType.Custom获取错误
EN

Stack Overflow用户
提问于 2021-05-10 07:06:46
回答 1查看 392关注 0票数 0

我试着在下一个例子中这样做:

https://js.devexpress.com/Demos/Widgetsgallery/Demo/DataGrid/CustomSummaries/NetCore/Light/

我已经尝试为我的网格创建一个自定义摘要。

例如,在下一张图片中,我有红色列和蓝色列,我想将其相加(在伪代码中)。

代码语言:javascript
复制
Sum = 0;
  if({RedColumn}.Value == D){
      Sum -= {BlueColumn}.Value
   }else{
      Sum += {BlueColumn}.Value
   }

我期望得到347.74 -218.46 +272.7 = 401.98,而不是838.9

我还创建了下一个方法(我知道它还没有完成,但我甚至没有进入这个方法,我得到了之前的错误):

代码语言:javascript
复制
 function CalculateCustomSummary(options) {
        if (options.name === "SelectedRowsSummary") {
            if (options.summaryProcess === "start") {
                options.CdAmt = 0;
            }
            if (options.summaryProcess === "calculate") {
                options.CdAmt = options.CdAmt + options.value.CdAmt;
            }
        }
    }

这是我的夏天:

代码语言:javascript
复制
   .Summary(s => s.GroupItems(items => items.AddFor(t=>t.CdAmt)
                    .Name("SelectedRowsSummary")
                    .ShowInColumn("CdAmt")
                    .DisplayFormat("Sum: {0}")
                    .ValueFormat(Format.Decimal)
                    .SummaryType(SummaryType.Custom)
             ).CalculateCustomSummary("CalculateCustomSummary"))

这是我在服务器端的加载操作(.LoadAction("{FuncName}"))

代码语言:javascript
复制
[HttpGet]
public async Task<IActionResult> {FuncName}(int Id, DataSourceLoadOptions loadOptions ... more params)
{
    try
    {
        IQueryable<X> hzInfos;
        hzInfos = _hService.GetAllHZ();  
        return Json(DataSourceLoader.Load(hzInfos, loadOptions));
    }
    catch (Exception ex)
    {
        _log.LogError($"Method Name: {System.Reflection.MethodBase.GetCurrentMethod().Name}, " +
           $"Exception: {ex}");
        return StatusCode(500);
    }
}

在下一行:return Json(DataSourceLoader.Load(hzInfos, loadOptions));

我有下一个错误:

“不支持指定的方法。”

“at DevExtreme.AspNet.Data.RemoteGrouping.RemoteGroupExpressionCompiler.GetPreAggregateMethodName(String summaryType)\r\n at DevExtreme.AspNet.Data.RemoteGrouping.RemoteGroupExpressionCompiler.MakeAggregate(Expression aggregateTarget,SummaryInfo s)\r\n at DevExtreme.AspNet.Data.RemoteGrouping.RemoteGroupExpressionCompiler.d__8.MoveNext()\r\n at System.Collections.Generic.List1.AddEnumerable(IEnumerable1枚举)\r\n在System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1集合)\r在DevExtreme.AspNet.Data.RemoteGrouping.RemoteGroupExpressionCompiler.MakeAggregatingProjection(Expression目标处,groupingType类型,\r\n在DevExtreme.AspNet.Data.RemoteGrouping.RemoteGroupExpressionCompiler.Compile(Expression目标)\r\n在DevExtreme.AspNet.Data.DataSourceExpressionBuilder.AddRemoteGrouping(Boolean suppressGroups,布尔suppressTotals)\r\n在DevExtreme.AspNet.Data.DataSourceExpressionBuilder.BuildLoadGroupsExpr(Boolean分页,布尔suppressGroups,\r\n在DevExtreme.AspNet.Data.DataSourceLoaderImpl1.<ExecRemoteGroupingAsync>d__13.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at DevExtreme.AspNet.Data.DataSourceLoaderImpl1.d__5.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task任务)\r\n在DevExtreme.AspNet.Data.DataSourceLoader.LoadT\r\n at CardTranzactions.Controllers.HovaZehutSTHZController.d__11.MoveNext()中{ path}

我能做些什么?

在另一次尝试中通过注释建议更改我的代码:

代码语言:javascript
复制
    [HttpGet]
    public async Task<IActionResult> {FuncName}(int Id, DataSourceLoadOptions loadOptions ... more params)
    {
        try
        {
            List<X> hzInfos;
            hzInfos = _hService.GetAllHZ().ToList();  
            return Json(DataSourceLoader.Load(hzInfos, loadOptions));
        }
        catch (Exception ex)
        {
            _log.LogError($"Method Name: {System.Reflection.MethodBase.GetCurrentMethod().Name}, " +
               $"Exception: {ex}");
            return StatusCode(500);
        }
    }
    
    
    
    
    
    
    
       at DevExtreme.AspNet.Data.Aggregation.AggregateCalculator`1.CreateAggregator(SummaryInfo summaryInfo)
       at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at DevExtreme.AspNet.Data.Aggregation.AggregateCalculator`1.ProcessGroup(Group group)
       at DevExtreme.AspNet.Data.Aggregation.AggregateCalculator`1.ProcessItem(Object item)
       at DevExtreme.AspNet.Data.Aggregation.AggregateCalculator`1.Run()
       at DevExtreme.AspNet.Data.DataSourceLoaderImpl`1.<ContinueWithAggregationAsync>d__9`1.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at DevExtreme.AspNet.Data.DataSourceLoaderImpl`1.<ContinueWithGroupingAsync>d__8`1.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at DevExtreme.AspNet.Data.DataSourceLoaderImpl`1.<LoadAsync>d__5.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at DevExtreme.AspNet.Data.DataSourceLoader.Load[T](IQueryable`1 source, DataSourceLoadOptionsBase options)
       at CardTranzactions.Controllers.HovaZehutSTHZController.<GetHZ>d__11.MoveNext() in {the path}
EN

回答 1

Stack Overflow用户

发布于 2021-05-18 14:04:15

尝试此解决方案,不要返回JSON,只需遵循WebApi .Net核心指南:

代码语言:javascript
复制
[HttpGet]
public async Task<object> {FuncName}(int Id, DataSourceLoadOptions loadOptions ... more params)
{
    try
    {
        return DataSourceLoader.Load(_hService.GetAllHZ(), loadOptions);
    }
    catch (Exception ex)
    {
        _log.LogError($"Method Name: {System.Reflection.MethodBase.GetCurrentMethod().Name}, " +
           $"Exception: {ex}");
        return StatusCode(500);
    }
}

还要确保remoteOperations.summaryremoteOperations.groupPagingremoteOperations属性没有设置或设置为false。

请参阅:https://demos.devexpress.com/ASPNetCore/Demo/DataGrid/WebAPIService/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67466169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档