-
Notifications
You must be signed in to change notification settings - Fork 133
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
[Bug Report]表格在表头分组情况下排序异常(无法正常排序、多列无法分别排序) #382
Comments
@GodExious 你好!我是Dosu,一个能够帮助你解决 bug、回答问题并帮助你成为贡献者的机器人。我会在等待人类维护者的过程中为你提供帮助。 表格在表头分组情况下排序异常,且多列无法分别排序的原因是 以下是 /**
* 表头分组
*/
children?: any[]; 例如,在 columns: [
{
title: 'Name',
key: 'name',
children: [
{
title: 'First Name',
key: 'firstName',
sortable: true
},
{
title: 'Last Name',
key: 'lastName',
sortable: true
}
]
},
{
title: 'Age',
key: 'age',
sortable: true
}
] 在这个配置中, 目前, |
@dosu 但是我需要把Age并入表头中,你这样只是投机取巧,并不能解决bug |
要在表头分组的情况下正确排序并保持 "Age" 列在分组表头中,你需要确保 "Age" 列在分组表头中正确定义,并且排序功能正确实现。 以下是一个示例,展示了如何在分组表头中定义 "Age" 列并确保其可排序: <template>
<div style="margin: 200px">
<Divider>表头分组(边框)</Divider>
<Table border :columns="columns11" :data="data10" height="500"></Table>
</div>
</template>
<script>
export default {
data () {
return {
data10: [
{"key":0,"name":"John Brown","age":1,"street":"Lake Park","building":"C","door":2035,"caddress":"Lake Street 42","cname":"SoftLake Co","gender":"M"},
{"key":1,"name":"John Brown","age":2,"street":"Lake Park","building":"C","door":2035,"caddress":"Lake Street 42","cname":"SoftLake Co","gender":"M"},
// ... more data
],
columns11: [
{
title: 'Name',
key: 'name',
align: 'center',
width: 200,
fixed: 'left',
filters: [
{
label: 'Joe',
value: 1
},
{
label: 'John',
value: 2
}
],
filterMultiple: false,
filterMethod (value, row) {
if (value === 1) {
return row.name === 'Joe';
} else if (value === 2) {
return row.name === 'John Brown';
}
}
},
{
title: 'Other',
align: 'center',
children: [
{
title: 'Age',
key: 'age',
align: 'center',
width: 200,
sortable: true
},
{
title: 'Address',
align: 'center',
children: [
{
title: 'Street',
key: 'street',
align: 'center',
width: 200
},
{
title: 'Block',
align: 'center',
children: [
{
title: 'Building',
key: 'building',
align: 'center',
width: 200
},
{
title: 'Door',
key: 'door',
align: 'center',
width: 200
}
]
}
]
}
]
}
]
};
}
};
</script> 在这个示例中,"Age" 列被定义在 "Other" 分组表头下,并设置为可排序。这应该有助于解决排序不正确的问题,并确保排序状态正确同步[1]. |
@dosu 事实上这还是投机取巧的方法,这个bug更为准确地来说是只有组内第一列的数据可以被正确排序,任何组内的其他可选排序列点击排序时将完全按照第一列的大小作为排序基准,从而无法正确排序,这是个实在的bug |
要解决组内只有第一列可以正确排序的问题,你需要确保每个可排序列都有独立的排序逻辑。以下是一个示例,展示了如何为每个可排序列定义独立的排序方法: <template>
<div style="margin: 200px">
<Divider>表头分组(边框)</Divider>
<Table border :columns="columns11" :data="data10" height="500"></Table>
</div>
</template>
<script>
export default {
data () {
return {
data10: [
{"key":0,"name":"John Brown","age":1,"street":"Lake Park","building":"C","door":2035,"caddress":"Lake Street 42","cname":"SoftLake Co","gender":"M"},
{"key":1,"name":"John Brown","age":2,"street":"Lake Park","building":"C","door":2035,"caddress":"Lake Street 42","cname":"SoftLake Co","gender":"M"},
// ... more data
],
columns11: [
{
title: 'Name',
key: 'name',
align: 'center',
width: 200,
fixed: 'left',
filters: [
{
label: 'Joe',
value: 1
},
{
label: 'John',
value: 2
}
],
filterMultiple: false,
filterMethod (value, row) {
if (value === 1) {
return row.name === 'Joe';
} else if (value === 2) {
return row.name === 'John Brown';
}
}
},
{
title: 'Other',
align: 'center',
children: [
{
title: 'Age',
key: 'age',
align: 'center',
width: 200,
sortable: true,
sortMethod (a, b) {
return a.age - b.age;
}
},
{
title: 'Address',
align: 'center',
children: [
{
title: 'Street',
key: 'street',
align: 'center',
width: 200
},
{
title: 'Block',
align: 'center',
children: [
{
title: 'Building',
key: 'building',
align: 'center',
width: 200,
sortable: true,
sortMethod (a, b) {
return a.building.localeCompare(b.building);
}
},
{
title: 'Door No.',
key: 'door',
align: 'center',
width: 200
}
]
}
]
}
]
}
]
};
}
};
</script> 在这个示例中, |
这个AI教使用者入门应该还是不错的,但是修bug不是他能做的,希望官方能把表格分组的排序异常bug修复了吧,谢谢~ |
生成一个表头可以解决 renderHeader: (h, params) => {
return h("div",
{
style:{
display: 'flex',
alignItems: 'center',
gap: '0px',
}
},
[
h("span",params.column.title),
h("div",
{
style: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '0px',
},
} ,
[
h(resolveComponent("Icon"), {
type: "ios-arrow-up",
onClick: () => {
console.log('正序排序');
},
}),
h(resolveComponent("Icon"), {
type: "ios-arrow-down",
onClick: () => {
console.log('倒序排序');
},
}),
]
)
]);
}, |
Environment
Windows11/Chrome/vue-cli 5.0.8
Reproduction link
https://run.iviewui.com/cQJt6zVd
Steps to reproduce
为表格的表头设置分组
【无法正常排序】
在第一个表格,点击“年龄”字段的排序按钮,排序结果不对。
【多列无法分别排序】
在第二个表格,点击任意一个字段的排序按钮,不仅排序结果不对,两个可排序字段的排序状态会被同步
What is expected?
选中的字段能正常排序,且不应该影响其他可排序字段的排序情况
What is actually happening?
选中的字段不能正常排序,其他可排序字段的排序情况会被一起同步
The text was updated successfully, but these errors were encountered: