mirror of https://github.com/ElemeFE/element
Table: Update docs for carbon table
parent
0ca040fb42
commit
8c78dc1082
|
@ -267,6 +267,32 @@
|
|||
|
||||
deleteRow(index, rows) {
|
||||
rows.splice(index, 1);
|
||||
},
|
||||
|
||||
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
if (columnIndex === 0) {
|
||||
return [1, 2];
|
||||
} else if (columnIndex === 1) {
|
||||
return [0, 0];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (columnIndex === 0) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
return {
|
||||
rowspan: 2,
|
||||
colspan: 1
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
rowspan: 0,
|
||||
colspan: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1681,6 +1707,145 @@ For table of numbers, you can add an extra row at the table footer displaying ea
|
|||
```
|
||||
:::
|
||||
|
||||
### 合并行或列
|
||||
|
||||
多行或多列共用一个数据时,可以合并行或列。
|
||||
:::demo 通过给`table`传入`span-method`方法可以实现合并行或列,方法的参数是一个对象,里面包含当前行`row`、当前列`column`、当前行号`rowIndex`、当前列号`columnIndex`四个属性。该函数可以返回一个二维数组,第一个元素代表`rowspan`,第二个元素代表`colspan`。 也可以返回一个键名为`rowsapn`和`colspan`的对象。
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div>
|
||||
<el-table
|
||||
:data="tableData6"
|
||||
:span-method="arraySpanMethod"
|
||||
border
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
prop="id"
|
||||
label="ID"
|
||||
width="180">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
label="姓名">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount1"
|
||||
sortable
|
||||
label="数值 1">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount2"
|
||||
sortable
|
||||
label="数值 2">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount3"
|
||||
sortable
|
||||
label="数值 3">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-table
|
||||
:data="tableData6"
|
||||
:span-method="objectSpanMethod"
|
||||
border
|
||||
height="200"
|
||||
style="width: 100%; margin-top: 20px">
|
||||
<el-table-column
|
||||
prop="id"
|
||||
label="ID"
|
||||
width="180">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
label="姓名">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount1"
|
||||
label="数值 1(元)">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount2"
|
||||
label="数值 2(元)">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount3"
|
||||
label="数值 3(元)">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
tableData6: [{
|
||||
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
|
||||
}]
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
if (columnIndex === 0) {
|
||||
return [1, 2];
|
||||
} else if (columnIndex === 1) {
|
||||
return [0, 0];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (columnIndex === 0) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
return {
|
||||
rowspan: 2,
|
||||
colspan: 1
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
rowspan: 0,
|
||||
colspan: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
```
|
||||
:::
|
||||
|
||||
### Table Attributes
|
||||
| Attribute | Description | Type | Accepted Values | Default |
|
||||
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
||||
|
@ -1704,6 +1869,7 @@ For table of numbers, you can add an extra row at the table footer displaying ea
|
|||
| show-summary | whether to display a summary row | Boolean | — | false |
|
||||
| sum-text | displayed text for the first column of summary row | String | — | Sum |
|
||||
| summary-method | custom summary method | Function({ columns, data }) | — | — |
|
||||
| span-method | 合并行或列的计算方法 | Function({ row, column, rowIndex, columnIndex }) | — | — |
|
||||
|
||||
### Table Events
|
||||
| Event Name | Description | Parameters |
|
||||
|
@ -1724,6 +1890,8 @@ For table of numbers, you can add an extra row at the table footer displaying ea
|
|||
| current-change | triggers when current row changes | currentRow, oldCurrentRow |
|
||||
| header-dragend | triggers when finish dragging header | newWidth, oldWidth, column, event |
|
||||
| expand | triggers when user expands or collapses a row | row, expanded |
|
||||
| sort-clear | 当调用清空排序条件的时候会触发该事件 | - |
|
||||
| filter-clear | 当调用清空条件的时候会触发该事件 | - |
|
||||
|
||||
### Table Methods
|
||||
| Method | Description | Parameters |
|
||||
|
@ -1731,11 +1899,13 @@ For table of numbers, you can add an extra row at the table footer displaying ea
|
|||
| clearSelection | used in multiple selection Table, clear selection, might be useful when `reserve-selection` is on | selection |
|
||||
| toggleRowSelection | used in multiple selection Table, toggle if a certain row is selected. With the second parameter, you can directly set if this row is selected | row, selected |
|
||||
| setCurrentRow | used in single selection Table, set a certain row selected. If called without any parameter, it will clear selection. | row |
|
||||
| clearSort | 用于清空排序条件,数据会恢复成未排序的状态 | - |
|
||||
| clearFilter | 用于清空过滤条件,数据会恢复成未过滤的状态 | - |
|
||||
|
||||
### Table Slot
|
||||
| Name | Description |
|
||||
|------|--------|
|
||||
| append | Contents to be inserted after the last row. It is still nested inside the `<tbody>` tag. You may need this slot if you want to implement infinite scroll for the table. This slot will be displayed above the summary row if there is one. |
|
||||
| append | Contents to be inserted after the last row. You may need this slot if you want to implement infinite scroll for the table. This slot will be displayed above the summary row if there is one. |
|
||||
|
||||
### Table-column Attributes
|
||||
| Attribute | Description | Type | Accepted Values | Default |
|
||||
|
@ -1749,7 +1919,7 @@ For table of numbers, you can add an extra row at the table footer displaying ea
|
|||
| fixed | whether column is fixed at left/right. Will be fixed at left if `true` | string/boolean | true/left/right | — |
|
||||
| render-header | render function for table header of this column | Function(h, { column, $index }) | — | — |
|
||||
| sortable | whether column can be sorted. Remote sorting can be done by setting this attribute to 'custom' and listening to the `sort-change` event of Table | boolean, string | true, false, custom | false |
|
||||
| sort-method | sorting method, works when `sortable` is `true`. Should return a boolean. | Function(a, b) | — | — |
|
||||
| sort-method | sorting method, works when `sortable` is `true`. 和 Array#sort 表现一致 | Function(a, b) | — | — |
|
||||
| resizable | whether column width can be resized, works when `border` of `el-table` is `true` | boolean | — | false |
|
||||
| formatter | function that formats cell content | Function(row, column, cellValue) | — | — |
|
||||
| show-overflow-tooltip | whether to hide extra content and show them in a tooltip when hovering on the cell | boolean | — | false |
|
||||
|
|
|
@ -309,6 +309,32 @@
|
|||
|
||||
deleteRow(index, rows) {
|
||||
rows.splice(index, 1);
|
||||
},
|
||||
|
||||
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
if (columnIndex === 0) {
|
||||
return [1, 2];
|
||||
} else if (columnIndex === 1) {
|
||||
return [0, 0];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (columnIndex === 0) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
return {
|
||||
rowspan: 2,
|
||||
colspan: 1
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
rowspan: 0,
|
||||
colspan: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1744,6 +1770,145 @@
|
|||
```
|
||||
:::
|
||||
|
||||
### 合并行或列
|
||||
|
||||
多行或多列共用一个数据时,可以合并行或列。
|
||||
:::demo 通过给`table`传入`span-method`方法可以实现合并行或列,方法的参数是一个对象,里面包含当前行`row`、当前列`column`、当前行号`rowIndex`、当前列号`columnIndex`四个属性。该函数可以返回一个二维数组,第一个元素代表`rowspan`,第二个元素代表`colspan`。 也可以返回一个键名为`rowsapn`和`colspan`的对象。
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div>
|
||||
<el-table
|
||||
:data="tableData6"
|
||||
:span-method="arraySpanMethod"
|
||||
border
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
prop="id"
|
||||
label="ID"
|
||||
width="180">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
label="姓名">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount1"
|
||||
sortable
|
||||
label="数值 1">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount2"
|
||||
sortable
|
||||
label="数值 2">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount3"
|
||||
sortable
|
||||
label="数值 3">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-table
|
||||
:data="tableData6"
|
||||
:span-method="objectSpanMethod"
|
||||
border
|
||||
height="200"
|
||||
style="width: 100%; margin-top: 20px">
|
||||
<el-table-column
|
||||
prop="id"
|
||||
label="ID"
|
||||
width="180">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
label="姓名">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount1"
|
||||
label="数值 1(元)">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount2"
|
||||
label="数值 2(元)">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="amount3"
|
||||
label="数值 3(元)">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
tableData6: [{
|
||||
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
|
||||
}]
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
if (columnIndex === 0) {
|
||||
return [1, 2];
|
||||
} else if (columnIndex === 1) {
|
||||
return [0, 0];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
if (columnIndex === 0) {
|
||||
if (rowIndex % 2 === 0) {
|
||||
return {
|
||||
rowspan: 2,
|
||||
colspan: 1
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
rowspan: 0,
|
||||
colspan: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
```
|
||||
:::
|
||||
|
||||
### Table Attributes
|
||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
||||
|
@ -1767,6 +1932,7 @@
|
|||
| show-summary | 是否在表尾显示合计行 | Boolean | — | false |
|
||||
| sum-text | 合计行第一列的文本 | String | — | 合计 |
|
||||
| summary-method | 自定义的合计计算方法 | Function({ columns, data }) | — | — |
|
||||
| span-method | 合并行或列的计算方法 | Function({ row, column, rowIndex, columnIndex }) | — | — |
|
||||
|
||||
### Table Events
|
||||
| 事件名 | 说明 | 参数 |
|
||||
|
@ -1787,6 +1953,8 @@
|
|||
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | currentRow, oldCurrentRow |
|
||||
| header-dragend | 当拖动表头改变了列的宽度的时候会触发该事件 | newWidth, oldWidth, column, event |
|
||||
| expand | 当用户对某一行展开或者关闭的上会触发该事件 | row, expanded |
|
||||
| sort-clear | 当调用清空排序条件的时候会触发该事件 | - |
|
||||
| filter-clear | 当调用清空条件的时候会触发该事件 | - |
|
||||
|
||||
### Table Methods
|
||||
| 方法名 | 说明 | 参数 |
|
||||
|
@ -1794,11 +1962,13 @@
|
|||
| clearSelection | 用于多选表格,清空用户的选择,当使用 reserve-selection 功能的时候,可能会需要使用此方法 | selection |
|
||||
| toggleRowSelection | 用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中) | row, selected |
|
||||
| setCurrentRow | 用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。 | row |
|
||||
| clearSort | 用于清空排序条件,数据会恢复成未排序的状态 | - |
|
||||
| clearFilter | 用于清空过滤条件,数据会恢复成未过滤的状态 | - |
|
||||
|
||||
### Table Slot
|
||||
| name | 说明 |
|
||||
|------|--------|
|
||||
| append | 插入至表格最后一行之后的内容,仍然位于 `<tbody>` 标签内。如果需要对表格的内容进行无限滚动操作,可能需要用到这个 slot。若表格有合计行,该 slot 会位于合计行之上。 |
|
||||
| append | 插入至表格最后一行之后的内容,如果需要对表格的内容进行无限滚动操作,可能需要用到这个 slot。若表格有合计行,该 slot 会位于合计行之上。 |
|
||||
|
||||
### Table-column Attributes
|
||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||
|
@ -1812,7 +1982,7 @@
|
|||
| fixed | 列是否固定在左侧或者右侧,true 表示固定在左侧 | string, boolean | true, left, right | — |
|
||||
| render-header | 列标题 Label 区域渲染使用的 Function | Function(h, { column, $index }) | — | — |
|
||||
| sortable | 对应列是否可以排序,如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件 | boolean, string | true, false, 'custom' | false |
|
||||
| sort-method | 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效,需返回一个布尔值 | Function(a, b) | — | — |
|
||||
| sort-method | 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效,和 Array#sort 表现一致 | Function(a, b) | — | — |
|
||||
| resizable | 对应列是否可以通过拖动改变宽度(需要在 el-table 上设置 border 属性为真) | boolean | — | true |
|
||||
| formatter | 用来格式化内容 | Function(row, column, cellValue) | — | — |
|
||||
| show-overflow-tooltip | 当内容过长被隐藏时显示 tooltip | Boolean | — | false |
|
||||
|
|
|
@ -255,8 +255,6 @@ export default {
|
|||
columnIndex
|
||||
});
|
||||
|
||||
console.log(result);
|
||||
|
||||
if (Array.isArray(result)) {
|
||||
rowspan = result[0];
|
||||
colspan = result[1];
|
||||
|
|
Loading…
Reference in New Issue