合并行

Former-commit-id: 80bdfce859a175114e69639bdec119b7f28383b3 [formerly 7e8742b94e50636c473709ef67fc92ee362a521c] [formerly 80bdfce859a175114e69639bdec119b7f28383b3 [formerly 7e8742b94e50636c473709ef67fc92ee362a521c] [formerly 80bdfce859a175114e69639bdec119b7f28383b3 [formerly 7e8742b94e50636c473709ef67fc92ee362a521c] [formerly 7e8742b94e50636c473709ef67fc92ee362a521c [formerly 2041b9949949dbca0bd964c5557e2dcddb95303a [formerly 9dcc76f94eb45430d2f99444d61a6ed28a67df04]]]]]
Former-commit-id: 7a046a638cbe4371a047be6eb8a3c5e04b5cd714
Former-commit-id: 1e0c24ab7dabecf892a170d5ac00893807f23345
Former-commit-id: ad0b0c4fbcce781d0ba0d6f28bc3fa297e1cbf5d [formerly 9e0f19ad4965cfed84acdf462f4f392448f1095d]
Former-commit-id: 1d051ac234e5ee97e1f78269551e1da7eb86354c
Former-commit-id: 0ef69b2a85496a4b78e97c89c7363a5e30fcabd5
Former-commit-id: dc44ea4032a76a3983dce62fcacbc60737410c41
Former-commit-id: 559e29f5b0a2016cb0f4714e37ac50bfd30e1720
Former-commit-id: 087134a1991cec33b65e28d12565fd6783fadc80
This commit is contained in:
孙昊翔
2018-08-28 10:40:17 +08:00
parent 40b1a82851
commit 983eab079d
5 changed files with 196 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ export default {
{ path: `${pre}demo10`, title: '多选' },
{ path: `${pre}demo11`, title: '排序' },
{ path: `${pre}demo12`, title: '筛选' },
{ path: `${pre}demo13`, title: '表尾合计行' }
{ path: `${pre}demo13`, title: '表尾合计行' },
{ path: `${pre}demo14`, title: '合并行' }
])('/demo/d2-crud/')
}

View File

@@ -0,0 +1,88 @@
export default `<template>
<div>
<d2-crud
:columns="columns"
:data="data"
:options="options"/>
</div>
</template>
<script>
export default {
data () {
return {
columns: [
{
title: 'ID',
key: 'id'
},
{
title: '姓名',
key: 'name'
},
{
title: '数值 1',
key: 'amount1'
},
{
title: '数值 2',
key: 'amount2'
},
{
title: '数值 3',
key: 'amount3'
}
],
data: [
{
id: '12987122',
name: '王小虎',
amount1: '234',
amount2: '3.2',
amount3: 10
},
{
id: '12987123',
name: '王小虎',
amount1: '165',
amount2: '4.43',
amount3: 12
},
{
id: '12987124',
name: '王小虎',
amount1: '324',
amount2: '1.9',
amount3: 9
},
{
id: '12987125',
name: '王小虎',
amount1: '621',
amount2: '2.2',
amount3: 17
},
{
id: '12987126',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 15
}
],
options: {
border: true,
spanMethod ({ row, column, rowIndex, columnIndex }) {
if (rowIndex % 2 === 0) {
if (columnIndex === 0) {
return [1, 2]
} else if (columnIndex === 1) {
return [0, 0]
}
}
}
}
}
}
}
</script>`

View File

@@ -0,0 +1 @@
通过给 `options` 传入 `spanMethod` 方法可以实现合并行,方法的参数是一个对象,里面包含当前行 `row` 、当前列 `column` 、当前行号 `rowIndex` 、当前列号 `columnIndex` 四个属性。该函数可以返回一个包含两个元素的数组第一个元素代表rowspan第二个元素代表colspan。代码如下

View File

@@ -0,0 +1,104 @@
<template>
<d2-container>
<template slot="header">合并行</template>
<d2-crud
:columns="columns"
:data="data"
:options="options">
</d2-crud>
<el-card shadow="never" class="d2-mb">
<d2-markdown :source="doc"/>
</el-card>
<el-card shadow="never" class="d2-mb">
<d2-highlight :code="code"/>
</el-card>
<template slot="footer">
<d2-link-btn title="D2 CRUD" link="https://github.com/d2-projects/d2-crud"/>
</template>
</d2-container>
</template>
<script>
import doc from './doc.md'
import code from './code.js'
export default {
data () {
return {
doc,
code,
columns: [
{
title: 'ID',
key: 'id'
},
{
title: '姓名',
key: 'name'
},
{
title: '数值 1',
key: 'amount1'
},
{
title: '数值 2',
key: 'amount2'
},
{
title: '数值 3',
key: 'amount3'
}
],
data: [
{
id: '12987122',
name: '王小虎',
amount1: '234',
amount2: '3.2',
amount3: 10
},
{
id: '12987123',
name: '王小虎',
amount1: '165',
amount2: '4.43',
amount3: 12
},
{
id: '12987124',
name: '王小虎',
amount1: '324',
amount2: '1.9',
amount3: 9
},
{
id: '12987125',
name: '王小虎',
amount1: '621',
amount2: '2.2',
amount3: 17
},
{
id: '12987126',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 15
}
],
options: {
border: true,
spanMethod ({ row, column, rowIndex, columnIndex }) {
if (rowIndex % 2 === 0) {
if (columnIndex === 0) {
return [1, 2]
} else if (columnIndex === 1) {
return [0, 0]
}
}
}
}
}
}
}
</script>

View File

@@ -1 +1 @@
d83b0a5150e283432ed572257131cc3dcfadd519
4e65388c5605f3cec8e0c073312fab0a4dbd14ba