vue antd a-table 合并相同列的单元格
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue
·
<template>
<a-table :columns="columns" :data-source="data" bordered>
<template slot="name" slot-scope="text">
<a>{{ text }}</a>
</template>
</a-table>
</template>
<script>
// In the fifth row, other columns are merged into first column
// by setting it's colSpan to be 0
var spanArr = [];
var ageArr = [];
var position = 0;
var positionage = 0;
//列合并
const renderContent = (value, row, index) => {
const obj = {
children: value,
attrs: {},
};
const _row = spanArr[index];
obj.attrs = {
rowSpan: _row,
};
return obj;
};
const renderContentAge = (value, row, index) => {
const obj = {
children: value,
attrs: {},
};
const _row = ageArr[index];
obj.attrs = {
rowSpan: _row,
};
return obj;
};
const rowspan = (userData) => {
spanArr = [];
ageArr = [];
position = 0;
positionage = 0;
userData.forEach((item, index) => {
if (index === 0) {
spanArr.push(1);
ageArr.push(1);
position = 0;
positionage = 0;
} else {
//需要合并的地方判断
if (userData[index].name === userData[index - 1].name) {
spanArr[position] += 1;
spanArr.push(0);
} else {
spanArr.push(1);
position = index;
}
if (userData[index].age === userData[index - 1].age) {
ageArr[positionage] += 1;
ageArr.push(0);
} else {
ageArr.push(1);
positionage = index;
}
}
});
console.log(spanArr);
console.log(ageArr);
};
const data = [
{
key: "1",
name: "aa",
age: 11,
tel: "0571-22098909",
phone: 18889898989,
address: "New York No. 1 Lake Park",
},
{
key: "2",
name: "aaa",
tel: "0571-22098333",
phone: 18889898888,
age: 11,
address: "London No. 1 Lake Park",
},
{
key: "3",
name: "aaa",
age: 32,
tel: "0575-22098909",
phone: 18900010002,
address: "Sidney No. 1 Lake Park",
},
{
key: "4",
name: "Jim Red",
age: 18,
tel: "0575-22098909",
phone: 18900010002,
address: "London No. 2 Lake Park",
},
{
key: "5",
name: "Jake White",
age: 18,
tel: "0575-22098909",
phone: 18900010002,
address: "Dublin No. 2 Lake Park",
},
];
export default {
data() {
const columns = [
{
title: "Name",
dataIndex: "name",
customRender: renderContent,
},
{
title: "Age",
dataIndex: "age",
customRender: renderContentAge,
},
{
title: "Home phone",
dataIndex: "tel",
},
{
title: "Phone",
dataIndex: "phone",
},
{
title: "Address",
dataIndex: "address",
},
];
return {
data,
columns,
};
},
created() {
rowspan(data);
},
};
</script>
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:4 个月前 )
9e887079
[skip ci] 1 年前
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)