Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 透视表,列小计的信息是自定义展示数据的,排序的时候没有正常排序 #2788

Closed
4 tasks
Dary-git opened this issue Jun 21, 2024 · 4 comments
Assignees

Comments

@Dary-git
Copy link

Dary-git commented Jun 21, 2024

🏷 Version

Package Version
@antv/s2 1.55.6
@antv/s2-react
@antv/s2-vue

Sheet Type

  • [✔] PivotSheet
  • TableSheet
  • GridAnalysisSheet
  • StrategySheet
  • EditableSheet

🖋 Description

数据中 “药店” 只有一条数据,属于列小计的信息,
排序“三级”按照 “P”排序 失效

⌨️ Code Snapshots

 const config = {
    "fields": {
        "rows": [
            "C_ee6137b3e25d6d414384c05a902440a7",
            "C_d7aab5be52d078d3fa64f3d21ecd0026"
        ],
        "columns": [],
        "values": [
            "C_5f2fa4430c08041fe03b8f637a23e807",
            "C_426d4e3fc3a206bd277a76590e763f92",
            "C_101abd1b2e279926aaf2ffcfdf3dd969"
        ]
    },
    "meta": [
        {
            "field": "C_ee6137b3e25d6d414384c05a902440a7",
            "name": "三级"
        },
        {
            "field": "C_d7aab5be52d078d3fa64f3d21ecd0026",
            "name": "门店"
        },
        {
            "field": "C_5f2fa4430c08041fe03b8f637a23e807",
            "name": "P"
        },
        {
            "field": "C_426d4e3fc3a206bd277a76590e763f92",
            "name": "系统"
        },
        {
            "field": "C_101abd1b2e279926aaf2ffcfdf3dd969",
            "name": "猎豹"
        }
    ],
    "data": [
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "618便利店福A区",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 2,
            "C_5f2fa4430c08041fe03b8f637a23e807": 2,
            "C_ee6137b3e25d6d414384c05a902440a7": "仓卖店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "美宜佳一东莞虎门龙眼工业路(粤33792店)",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 1,
            "C_5f2fa4430c08041fe03b8f637a23e807": 1,
            "C_ee6137b3e25d6d414384c05a902440a7": "大众便利店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "建军烟酒门市",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 4,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "食杂店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "茜阳烟酒",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 3,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "烟酒店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "松竹训春",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 2,
            "C_ee6137b3e25d6d414384c05a902440a7": "独立小型超市"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "星新批发部",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "仓卖店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "常瑞商店",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 4,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "烟酒店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "华诚商行",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "仓卖店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "红番茄超市",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "仓卖店"
        },
        {
            "C_d7aab5be52d078d3fa64f3d21ecd0026": "果果生活超市",
            "C_101abd1b2e279926aaf2ffcfdf3dd969": 0,
            "C_426d4e3fc3a206bd277a76590e763f92": 4,
            "C_5f2fa4430c08041fe03b8f637a23e807": 4,
            "C_ee6137b3e25d6d414384c05a902440a7": "仓卖店"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "3707",
            "C_426d4e3fc3a206bd277a76590e763f92": "29733",
            "C_5f2fa4430c08041fe03b8f637a23e807": "25976",
            "C_ee6137b3e25d6d414384c05a902440a7": "药店"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "2200",
            "C_426d4e3fc3a206bd277a76590e763f92": "11207",
            "C_5f2fa4430c08041fe03b8f637a23e807": "9635",
            "C_ee6137b3e25d6d414384c05a902440a7": "线下喜铺"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "1612",
            "C_426d4e3fc3a206bd277a76590e763f92": "4918",
            "C_5f2fa4430c08041fe03b8f637a23e807": "4237",
            "C_ee6137b3e25d6d414384c05a902440a7": "火车站售点"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "280772",
            "C_426d4e3fc3a206bd277a76590e763f92": "507413",
            "C_5f2fa4430c08041fe03b8f637a23e807": "402386",
            "C_ee6137b3e25d6d414384c05a902440a7": "烟酒店"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "84",
            "C_426d4e3fc3a206bd277a76590e763f92": "846",
            "C_5f2fa4430c08041fe03b8f637a23e807": "582",
            "C_ee6137b3e25d6d414384c05a902440a7": "飞机场售点"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "525173",
            "C_426d4e3fc3a206bd277a76590e763f92": "1040014",
            "C_5f2fa4430c08041fe03b8f637a23e807": "848189",
            "C_ee6137b3e25d6d414384c05a902440a7": "仓卖店"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "648",
            "C_426d4e3fc3a206bd277a76590e763f92": "2175",
            "C_5f2fa4430c08041fe03b8f637a23e807": "1497",
            "C_ee6137b3e25d6d414384c05a902440a7": "封闭场景"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "816463",
            "C_426d4e3fc3a206bd277a76590e763f92": "1604323",
            "C_5f2fa4430c08041fe03b8f637a23e807": "1288484",
            "C_ee6137b3e25d6d414384c05a902440a7": "食杂店"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "43990",
            "C_426d4e3fc3a206bd277a76590e763f92": "45140",
            "C_5f2fa4430c08041fe03b8f637a23e807": "41112",
            "C_ee6137b3e25d6d414384c05a902440a7": "镇街区批发"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "2102",
            "C_426d4e3fc3a206bd277a76590e763f92": "4451",
            "C_5f2fa4430c08041fe03b8f637a23e807": "1769",
            "C_ee6137b3e25d6d414384c05a902440a7": "O2O前置仓"
        },
        {
            "C_101abd1b2e279926aaf2ffcfdf3dd969": "2476618",
            "C_426d4e3fc3a206bd277a76590e763f92": "5064568",
            "C_5f2fa4430c08041fe03b8f637a23e807": "4211466"
        }
    ],
    "sortParams": [
        {
            "sortFieldId": "C_ee6137b3e25d6d414384c05a902440a7",
            sortByMeasure: 'C_5f2fa4430c08041fe03b8f637a23e807',
            sortMethod: 'asc',
            sortFunc: (params) => {
                const data = params.data.sort((a, b) => {
                    const a1 = a[params.sortByMeasure]
                    const b1 = b[params.sortByMeasure]
                    if (params.sortMethod === 'asc') return a1 - b1
                    else if (params.sortMethod === 'desc') return b1 - a1
                }).map(v => v[params.sortFieldId])
                console.log(params, data)
                return data
            }
        },
    ],
}

const options = {
    "width": 1129,
    "height": 716,
    "style": {
        "colCfg": {
            "height": 36
        },
        "cellCfg": {
            "height": 36
        },
        "layoutWidthType": "compact",
        "hierarchyCollapse": true
    },
    "totals": {
        "row": {
            "showGrandTotals": true,
            "showSubTotals": true,
            "reverseLayout": false,
            "reverseSubLayout": false,
            "label": "总计",
            "subLabel": "小计",
            "subTotalsDimensions": [
                "C_ee6137b3e25d6d414384c05a902440a7",
                "C_d7aab5be52d078d3fa64f3d21ecd0026"
            ],
            "calcTotals": {
                "aggregation": "SUM"
            },
            "calcSubTotals": {
                "aggregation": "SUM"
            }
        },
        "col": {
            "showGrandTotals": false,
            "showSubTotals": false,
            "reverseLayout": false,
            "reverseSubLayout": false,
            "label": "总计",
            "subLabel": "小计",
            "subTotalsDimensions": [],
            "calcTotals": {
                "aggregation": "SUM"
            },
            "calcSubTotals": {
                "aggregation": "SUM"
            }
        },
        "modifyName": "col",
        "propertyName": "total-cfg"
    },
    "conditions": {
        "text": [],
        "background": [],
        "icon": []
    },
    "hierarchyType": "tree",
}

const theme = {
    "background": {
        "color": "#00000000"
    },
    "splitLine": {
        "horizontalBorderColor": "rgba(219,219,219,1)",
        "verticalBorderColor": "rgba(219,219,219,1)"
    },
    "cornerCell": {
        "cell": {
            "backgroundColor": "rgba(233,237,250,1)",
            "horizontalBorderColor": "rgba(219,219,219,1)",
            "verticalBorderColor": "rgba(219,219,219,1)",
            "verticalBorderWidth": 1
        },
        "text": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "bolderText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "measureText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        }
    },
    "rowCell": {
        "cell": {
            "backgroundColor": "rgba(233,237,250,1)",
            "horizontalBorderColor": "rgba(219,219,219,1)",
            "verticalBorderColor": "rgba(219,219,219,1)",
            "interactionState": {
                "selected": {
                    "backgroundColor": "#ecf2fe",
                    "borderWidth": "3",
                    "borderColor": "",
                    "borderOpacity": 1
                }
            }
        },
        "text": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left",
            "textBaseline": "top"
        },
        "bolderText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "measureText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "seriesNumberWidth": 110
    },
    "colCell": {
        "cell": {
            "backgroundColor": "rgba(233,237,250,1)",
            "horizontalBorderColor": "rgba(219,219,219,1)",
            "verticalBorderColor": "rgba(219,219,219,1)",
            "interactionState": {
                "selected": {
                    "backgroundColor": "#ecf2fe",
                    "borderWidth": "3",
                    "borderColor": "",
                    "borderOpacity": 1
                }
            }
        },
        "text": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "bolderText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "measureText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "left"
        },
        "icon": {
            "size": 14
        }
    },
    "dataCell": {
        "cell": {
            "backgroundColor": "rgba(255,255,255,1)",
            "horizontalBorderColor": "rgba(219,219,219,1)",
            "verticalBorderColor": "rgba(219,219,219,1)",
            "interactionState": {
                "selected": {
                    "backgroundColor": "#ecf2fe",
                    "borderWidth": "3",
                    "borderColor": "",
                    "borderOpacity": 1
                }
            }
        },
        "text": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "right"
        },
        "bolderText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "right"
        },
        "measureText": {
            "fill": "#666666",
            "fontSize": 13,
            "textAlign": "right"
        }
    }
}
const s2 = new PivotSheet(container, config, options);

s2.setThemeCfg({ theme: theme })
s2.render();

🔗 Reproduce Link

image

🤔 Steps to Reproduce

😊 Expected Behavior

😅 Current Behavior

💻 System information

Environment Info
System
Browser
Copy link
Contributor

github-actions bot commented Jun 21, 2024

你要找的是不是 (You may look for issues):

  1. 85% 🐛 #2785

@lijinke666
Copy link
Member

排序的时候没有正常排序

没看懂你的问题, 预期是怎么排?

@Dary-git
Copy link
Author

排序的时候没有正常排序

没看懂你的问题, 预期是怎么排?

代码中 我设置了 “三级” 这一列维度,根据 “P” 这一列的数据排序,但是从图片上看排序是失败的

@lijinke666
Copy link
Member

lijinke666 commented Jun 27, 2024

看起来你期望的是在树状模式下, 根据特定数值对一级维度进行排序, 那么树状模式的一级维度本质上就是 行小计

image

所以本质上是对 三级 的行小计, 根据 P 进行排序, 这样修改:

import { TOTAL_VALUE, EXTRA_FIELD } from '@antv/s2';

sortParams: [
  {
    sortFieldId: 'C_ee6137b3e25d6d414384c05a902440a7',
    sortMethod: 'asc',
    sortByMeasure: TOTAL_VALUE,
    query: {
      [EXTRA_FIELD]: 'C_5f2fa4430c08041fe03b8f637a23e807',
    },
  },
]

image
image

可以看下这个文档: https://s2.antv.antgroup.com/manual/basic/sort/basic#3-%E5%BA%A6%E9%87%8F%E5%80%BC%E5%AD%97%E6%AE%B5sortbymeasure

@lijinke666 lijinke666 self-assigned this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants