>小计:是指数字列表的一部分的总和 >纵向分组小计:是指每个纵向分组下的小计 # 纵向分组小计 [TOC] ## 示例1—不存在横向分组小计 ### 1、效果展示 纵向分组小计:[点击预览示例1](https://bootapi.jeecg.com/jmreport/view/590808622016319488) 以地区为分组依据,计算销售金额合计;`合计`两个字展示在省份下。 ![](https://img.kancloud.cn/6c/e2/6ce2950639113e8e682cfa149f1b2ddb_615x387.png) ### 2、创建一个名为`区域省份销售统计`的数据报表 > 创建一个区域销售表,有七个字段:ID、数量、区域名称、年、省份、价格、月份 ![](https://img.kancloud.cn/70/ea/70ea527bff8715bfb137ba1298a7d933_808x210.png) #### 2.1 为`区域省份销售统计`创建SQL数据源 ![](https://img.kancloud.cn/4b/53/4b535eb44bce8c1f69a10f39263b6773_1917x891.png) >部分数据展示 ![](https://img.kancloud.cn/d9/b5/d9b50cfb8139f5c35463aff51dc2f3e1_1920x896.png) #### 2.2 将字段拖拽到设计器页面 ![](https://img.kancloud.cn/51/91/51912bbe74cf314d94cb0459f637e76c_1919x909.png) #### 2.3 设置纵向分组、横向分组、动态属性 >[danger]此步骤涉及到`横向纵向组合动态列`和`交叉报表` 横向纵向组合动态列请参考 [横向纵向组合动态列](http://report.jeecg.com/2119057) 交叉报表请参考 [交叉报表](http://report.jeecg.com/2112709) * 地区(areaname)纵向分组: `#{jm.group(areaname)}` * 省份(province)纵向分组:` #{jm.group(province)}` * 年份(year)横向分组: `#{jm.groupRight(year)}年` * 月份(month)横向分组: `#{jm.groupRight(month)}月` * 销售额(amount)动态属性:`#{jm.dynamic(amount)}` ![](https://img.kancloud.cn/ef/a9/efa9d105be87756fdfaac041eea63985_1332x895.png) #### 2. 4、重点来了->设置分组小计 >[danger] 特别注意:本例中` #{jm.group(areaname)}`为分组依据字段、`#{jm.group(province)}`为分组字段,则合计可正常显示,”合计“两个字展示在省份下;自1.4.0版本开始当只有分组依据字段,无其他分组字段时,”合计“两个字自动展示在分组字段后一个字段中。 >`#{jm.group(areaname)}`设置为分组依据 ![](https://img.kancloud.cn/79/bc/79bc09fe21d8ef882fa2fdab3584ccaa_1636x852.png) >`#{jm.dynamic(amount)}`设置为`求和` ![](https://img.kancloud.cn/01/ee/01ee995044c2b89fbb17f797b2b2aa27_1638x898.png) >保存预览 ![](https://img.kancloud.cn/92/7c/927c6e0523a9e39ac5a4f86ea5001d71_1911x980.png) ## 示例2—存在横向分组小计 ### 1、效果展示 组合分组小计:[点击预览示例2](https://bootapi.jeecg.com/jmreport/view/590812531803901952) 以区域为分组依据,设置纵向小计和横向小计 小计:横向计算,单价*金额 合计:金额列组内相加 ![](https://img.kancloud.cn/db/fd/dbfd1dfd8facf727dbad7bc72f6d9038_998x520.png) ### 2、创建一个名为`区域省份销售统计`的数据报表 > 创建一个区域销售表,有七个字段:ID、数量、区域名称、年、省份、价格、月份 ![](https://img.kancloud.cn/70/ea/70ea527bff8715bfb137ba1298a7d933_808x210.png) #### 2.1 为`区域省份销售统计`创建SQL数据源 ![](https://img.kancloud.cn/4b/53/4b535eb44bce8c1f69a10f39263b6773_1917x891.png) >部分数据展示 ![](https://img.kancloud.cn/d9/b5/d9b50cfb8139f5c35463aff51dc2f3e1_1920x896.png) #### 2.2 将字段拖拽到设计器页面 ![](https://img.kancloud.cn/da/2c/da2c2069b85fcf956f6a85bda41d7cda_1920x906.png) #### 2.3 设置横向分组、纵向分组、动态属性、横向小计 >[danger]此步骤涉及到`横向纵向组合动态列`和`交叉报表`和`横向分组小计` 横向纵向组合动态列请参考 [横向纵向组合动态列](http://report.jeecg.com/2119057) 交叉报表请参考 [交叉报表](http://report.jeecg.com/2112709) 横向分组小计请参考 [横向分组小计](http://report.jeecg.com/2250464) * 地区(areaname)纵向分组: `#{jm.group(areaname)}` * 部门(province)纵向分组: `#{jm.group(province)}` * 年份(year)横向分组: `#{jm.groupRight(year)}年` * 月份(month)横向分组: `#{jm.groupRight(month)}月` * 动态字段: 单价(`#{jm.dynamic(price)}`) 金额(`#{jm.dynamic(amount)}`) 小计(`#{jm.compute(price*amount)}`) ![](https://img.kancloud.cn/78/7f/787fb4c16bfae0ef8f0a82853d30b076_1337x850.png) #### 2.4、重点来了->设置分组小计 >[danger] 特别注意:本例中`#{jm.group(areaname)}`为分组依据字段、`#{jm.group(dept)}`为分组字段,则合计可正常显示,”合计“两个字展示在省份下;自1.4.0版本开始当只有分组依据字段,无其他分组字段时,”合计“两个字自动展示在分组字段后一个字段中。 > `#{jm.group(areaname)}`设置为分组依据 ![](https://img.kancloud.cn/85/45/85458035925469cb617cded0a53b4390_1636x848.png) >`#{jm.dynamic(amount)}`设置成求和列 ![](https://img.kancloud.cn/63/0e/630e3c6a51e4b7ca90d3c80b33b0aa5a_1646x845.png) >保存预览 ![](https://img.kancloud.cn/d2/31/d2310abc4a48716c3b0b0b03fc473a20_1911x980.png) ## 特殊规则注意 >[danger]设置动态单元格类型 当数据不完整时系统默认会进行补0操作便于小计表达式计算,如果该单元格不是数值类型则需要设置为文本,设置文本后该单元格显示为空;如:`备注`字段为空时,不需要展示为0,则设置备注字段类型为`文本`。 ![](https://img.kancloud.cn/0f/52/0f52e2c01175cae3ecc01d83315885d1_1177x532.png) ## 数据格式 重要!!!(数据必须完整) >[danger] 特别注意:当有横向分组时,数据中第一条`数据必须完整`;例如:期望展示1-12月的数据,则第一条数据1-12月必须都有数据。 * SQL数据: ![](https://img.kancloud.cn/83/53/8353142445f8c452572c3d7eec73ebd1_682x569.png) * 返回JSON格式: ``` { "data": [{ "amount": "100", "month": "1", "areaname": "华北", "year": "2020", "price": "5", "id": "1", "dept": "河北", "settleamount": "100" }, { "amount": "200", "month": "2", "areaname": "华北", "year": "2020", "price": "5", "id": "10", "dept": "河北", "settleamount": "200" }, { "amount": "202", "month": "2", "areaname": "华北", "year": "2020", "price": "6", "id": "12", "dept": "河南", "settleamount": "202" }, { "amount": "203", "month": "1", "areaname": "华东", "year": "2020", "price": "6", "id": "13", "dept": "辽宁", "settleamount": "203" }, { "amount": "204", "month": "2", "areaname": "华东", "year": "2020", "price": "6", "id": "14", "dept": "辽宁", "settleamount": "204" }, { "amount": "205", "month": "1", "areaname": "华南", "year": "2020", "price": "5", "id": "15", "dept": "湖北", "settleamount": "205" }, { "amount": "206", "month": "2", "areaname": "华南", "year": "2020", "price": "5", "id": "16", "dept": "湖北", "settleamount": "206" }, { "amount": "207", "month": "1", "areaname": "华南", "year": "2020", "price": "5", "id": "17", "dept": "安徽", "settleamount": "207" }, { "amount": "208", "month": "2", "areaname": "华南", "year": "2020", "price": "5", "id": "18", "dept": "安徽", "settleamount": "208" }, { "amount": "201", "month": "2", "areaname": "华北", "year": "2021", "price": "5", "id": "20", "dept": "河北", "settleamount": "201" }, { "amount": "200", "month": "1", "areaname": "华北", "year": "2021", "price": "5", "id": "21", "dept": "河北", "settleamount": "200" }, { "amount": "202", "month": "2", "areaname": "华北", "year": "2021", "price": "6", "id": "22", "dept": "河南", "settleamount": "202" }, { "amount": "209", "month": "1", "areaname": "华北", "year": "2021", "price": "6", "id": "23", "dept": "河南", "settleamount": "209" }, { "amount": "202", "month": "1", "areaname": "华北", "year": "2020", "price": "6", "id": "24", "dept": "河南", "settleamount": "202" }, { "amount": "203", "month": "1", "areaname": "华东", "year": "2021", "price": "6", "id": "25", "dept": "辽宁", "settleamount": "203" }, { "amount": "204", "month": "2", "areaname": "华东", "year": "2021", "price": "6", "id": "26", "dept": "辽宁", "settleamount": "204" }, { "amount": "205", "month": "1", "areaname": "华南", "year": "2021", "price": "5", "id": "27", "dept": "湖北", "settleamount": "205" }, { "amount": "206", "month": "2", "areaname": "华南", "year": "2021", "price": "5", "id": "28", "dept": "湖北", "settleamount": "206" }, { "amount": "207", "month": "1", "areaname": "华南", "year": "2021", "price": "5", "id": "29", "dept": "安徽", "settleamount": "207" }, { "amount": "208", "month": "2", "areaname": "华南", "year": "2021", "price": "5", "id": "30", "dept": "安徽", "settleamount": "208" }, { "amount": "203", "month": "1", "areaname": "华东", "year": "2020", "price": "6", "id": "43", "dept": "天津", "settleamount": "203" }, { "amount": "204", "month": "2", "areaname": "华东", "year": "2020", "price": "6", "id": "44", "dept": "天津", "settleamount": "204" }, { "amount": "203", "month": "1", "areaname": "华东", "year": "2021", "price": "6", "id": "45", "dept": "天津", "settleamount": "203" }, { "amount": "204", "month": "2", "areaname": "华东", "year": "2021", "price": "6", "id": "46", "dept": "天津", "settleamount": "204" }] } ```