grid添加合计功能

效果图

dataSource.png

前段代码

grid.png

注意点:

  • serverAggregates: true,
  • aggregate: [{field: "wareAmt", aggregate: "sum"}]

后段代码

controller类

public AggregatesResponseData queryTotal(FsUseFund dto, @RequestParam(defaultValue = DEFAULT_PAGE) int page,
                                             @RequestParam(defaultValue = DEFAULT_PAGE_SIZE) int pageSize, HttpServletRequest request) {
        IRequest requestContext = createRequestContext(request);
        AggregatesResponseData aggregatesResponseData = service.selectSumUseFundNew(requestContext, dto, page, pageSize);
        return aggregatesResponseData;
    }

controller返回的是AggregatesResponseData数据

service类

Map> aggregates=new HashMap<>();
Map wareAmtSumA=new HashMap<>(); 
wareAmtSumA.put(FsUseFund.AGGREGATE_SUM,wareAmtSum);
aggregates.put(FsUseFund.FIELD_WARE_AMT,wareAmtSumA);


AggregatesResponseData aggregatesResponseData = new AggregatesResponseData(fsUseFunds);
aggregatesResponseData.setAggregates(aggregates);
return aggregatesResponseData;

fsUseFunds存的是需要返回前台的List数据
aggregates存的是map函数,里面包含各列的数据。各列的数据是以map的形式存储。
FsUseFund.FIELD_WARE_AMT是前台的列名字段,
FsUseFund.AGGREGATE_SUM是sum

你可能感兴趣的:(grid添加合计功能)