Select second row
@@ -794,38 +688,44 @@ Single row selection is supported.
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-02',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-04',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-01',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }],
- currentRow: null
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-02',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ ],
+ currentRow: null,
}
},
methods: {
setCurrent(row) {
- this.$refs.singleTable.setCurrentRow(row);
+ this.$refs.singleTable.setCurrentRow(row)
},
handleCurrentChange(val) {
- this.currentRow = val;
- }
- }
+ this.currentRow = val
+ },
+ },
}
```
+
:::
### Multiple select
@@ -833,35 +733,28 @@ Single row selection is supported.
You can also select multiple rows.
:::demo Activating multiple selection is easy: simply add an `el-table-column` with its `type` set to `selection`. Apart from multiple selection, this example also uses `show-overflow-tooltip`: by default, if the content is too long, it will break into multiple lines. If you want to keep it in one line, use attribute `show-overflow-tooltip`, which accepts a `Boolean` value. When set `true`, the extra content will show in tooltip when hover on the cell.
+
```html
-
-
-
+ @selection-change="handleSelectionChange"
+ >
+
+
{{ scope.row.date }}
-
+
-
+
- Toggle selection status of second and third rows
+ Toggle selection status of second and third rows
Clear selection
@@ -870,36 +763,44 @@ You can also select multiple rows.
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-02',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-04',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-01',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-08',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-06',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-07',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }],
- multipleSelection: []
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-02',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-08',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-06',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-07',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ ],
+ multipleSelection: [],
}
},
@@ -907,19 +808,20 @@ You can also select multiple rows.
toggleSelection(rows) {
if (rows) {
rows.forEach(row => {
- this.$refs.multipleTable.toggleRowSelection(row);
- });
+ this.$refs.multipleTable.toggleRowSelection(row)
+ })
} else {
- this.$refs.multipleTable.clearSelection();
+ this.$refs.multipleTable.clearSelection()
}
},
handleSelectionChange(val) {
- this.multipleSelection = val;
- }
- }
+ this.multipleSelection = val
+ },
+ },
}
```
+
:::
### Sorting
@@ -927,27 +829,18 @@ You can also select multiple rows.
Sort the data to find or compare data quickly.
:::demo Set attribute `sortable` in a certain column to sort the data based on this column. It accepts `Boolean` with a default value `false`. Set table attribute `default-sort` to determine default sort column and order. To apply your own sorting rules, use `sort-method` or `sort-by`. If you need remote sorting from backend, set `sortable` to `custom`, and listen to the `sort-change` event on Table. In the event handler, you have access to the sorting column and sorting order so that you can fetch sorted table data from API. In this example we use another attribute named `formatter` to format the value of certain columns. It accepts a function which has two parameters: `row` and `column`. You can handle it according to your own needs.
+
```html
-
+ :default-sort="{prop: 'date', order: 'descending'}"
+ style="width: 100%"
+ >
+
-
-
-
+
+
@@ -956,33 +849,39 @@ Sort the data to find or compare data quickly.
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-02',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-04',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-01',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }]
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-02',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ ],
}
},
methods: {
formatter(row, column) {
- return row.address;
- }
- }
+ return row.address
+ },
+ },
}
```
+
:::
### Filter
@@ -990,6 +889,7 @@ Sort the data to find or compare data quickly.
Filter the table to find desired data.
:::demo Set attribute `filters` and `filter-method` in `el-table-column` makes this column filterable. `filters` is an array, and `filter-method` is a function deciding which rows are displayed. It has three parameters: `value`, `row` and `column`.
+
```html
reset date filter
@@ -998,7 +898,8 @@ Filter the table to find desired data.
row-key="date"
ref="filterTable"
:data="tableData"
- style="width: 100%">
+ style="width: 100%"
+ >
-
-
-
+
+
+ filter-placement="bottom-end"
+ >
{{scope.row.tag}}
+ disable-transitions
+ >{{scope.row.tag}}
@@ -1039,72 +936,73 @@ Filter the table to find desired data.
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- tag: 'Home'
- }, {
- date: '2016-05-02',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- tag: 'Office'
- }, {
- date: '2016-05-04',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- tag: 'Home'
- }, {
- date: '2016-05-01',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- tag: 'Office'
- }]
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ tag: 'Home',
+ },
+ {
+ date: '2016-05-02',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ tag: 'Office',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ tag: 'Home',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ tag: 'Office',
+ },
+ ],
}
},
methods: {
resetDateFilter() {
- this.$refs.filterTable.clearFilter('date');
+ this.$refs.filterTable.clearFilter('date')
},
clearFilter() {
- this.$refs.filterTable.clearFilter();
+ this.$refs.filterTable.clearFilter()
},
formatter(row, column) {
- return row.address;
+ return row.address
},
filterTag(value, row) {
- return row.tag === value;
+ return row.tag === value
},
filterHandler(value, row, column) {
- const property = column['property'];
- return row[property] === value;
- }
- }
+ const property = column['property']
+ return row[property] === value
+ },
+ },
}
```
+
:::
### Custom column template
Customize table column so it can be integrated with other components.
-:::demo You have access to the following data: row, column, $index and store (state management of Table) by [slot](https://v3.vuejs.org/guide/component-slots.html).
+:::demo You have access to the following data: row, column, \$index and store (state management of Table) by [slot](https://v3.vuejs.org/guide/component-slots.html).
+
```html
-
-
+
+
{{ scope.row.date }}
-
+
@@ -1119,16 +1017,17 @@ Customize table column so it can be integrated with other components.
-
+
- Edit
+ Edit
Delete
+ @click="handleDelete(scope.$index, scope.row)"
+ >Delete
@@ -1138,71 +1037,71 @@ Customize table column so it can be integrated with other components.
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-02',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-04',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-01',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }]
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-02',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ ],
}
},
methods: {
handleEdit(index, row) {
- console.log(index, row);
+ console.log(index, row)
},
handleDelete(index, row) {
- console.log(index, row);
- }
- }
+ console.log(index, row)
+ },
+ },
}
```
+
:::
### Table with custom header
Customize table header so it can be even more customized.
:::demo You can customize how the header looks by header [slots](https://v3.vuejs.org/guide/component-slots.html).
+
```html
-
-
-
-
-
+ style="width: 100%"
+ >
+
+
+
-
+
- Edit
+ Edit
Delete
+ @click="handleDelete(scope.$index, scope.row)"
+ >Delete
@@ -1212,48 +1111,53 @@ Customize table header so it can be even more customized.
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-02',
- name: 'John',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-04',
- name: 'Morgan',
- address: 'No. 189, Grove St, Los Angeles'
- }, {
- date: '2016-05-01',
- name: 'Jessy',
- address: 'No. 189, Grove St, Los Angeles'
- }],
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-02',
+ name: 'John',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Morgan',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Jessy',
+ address: 'No. 189, Grove St, Los Angeles',
+ },
+ ],
search: '',
}
},
methods: {
handleEdit(index, row) {
- console.log(index, row);
+ console.log(index, row)
},
handleDelete(index, row) {
- console.log(index, row);
- }
+ console.log(index, row)
+ },
},
}
```
+
:::
### Expandable row
When the row content is too long and you do not want to display the horizontal scroll bar, you can use the expandable row feature.
:::demo Activate expandable row by adding type="expand" and slot. The template for el-table-column will be rendered as the contents of the expanded row, and you can access the same attributes as when you are using `slot` in custom column templates.
+
```html
-
+
State: {{ props.row.state }}
@@ -1262,14 +1166,8 @@ When the row content is too long and you do not want to display the horizontal s
Zip: {{ props.row.zip }}
-
-
-
-
+
+
@@ -1277,61 +1175,70 @@ When the row content is too long and you do not want to display the horizontal s
export default {
data() {
return {
- tableData: [{
- date: '2016-05-03',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }, {
- date: '2016-05-02',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }, {
- date: '2016-05-04',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }, {
- date: '2016-05-01',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }, {
- date: '2016-05-08',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }, {
- date: '2016-05-06',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }, {
- date: '2016-05-07',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036'
- }]
+ tableData: [
+ {
+ date: '2016-05-03',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ {
+ date: '2016-05-02',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ {
+ date: '2016-05-04',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ {
+ date: '2016-05-01',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ {
+ date: '2016-05-08',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ {
+ date: '2016-05-06',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ {
+ date: '2016-05-07',
+ name: 'Tom',
+ state: 'California',
+ city: 'Los Angeles',
+ address: 'No. 189, Grove St, Los Angeles',
+ zip: 'CA 90036',
+ },
+ ],
}
- }
+ },
}
```
+
:::
### Tree data and lazy mode
@@ -1340,96 +1247,95 @@ When the row content is too long and you do not want to display the horizontal s
```html
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
```
+
:::
### Summary row
For table of numbers, you can add an extra row at the table footer displaying each column's sum.
:::demo You can add the summary row by setting `show-summary` to `true`. By default, for the summary row, the first column does not sum anything up but always displays 'Sum' (you can configure the displayed text using `sum-text`), while other columns sum every number in that column up and display them. You can of course define your own sum behaviour. To do so, pass a method to `summary-method`, which returns an array, and each element of the returned array will be displayed in the columns of the summary row. The second table of this example is a detailed demo.
+
```html
-
-
+
+
+
+
-
+
-
-
-
-
-
+
@@ -1497,28 +1386,13 @@ For table of numbers, you can add an extra row at the table footer displaying ea
height="200"
:summary-method="getSummaries"
show-summary
- style="width: 100%; margin-top: 20px">
-
-
-
-
-
-
-
-
-
-
+ style="width: 100%; margin-top: 20px"
+ >
+
+
+
+
+
@@ -1526,69 +1400,78 @@ For table of numbers, you can add an extra row at the table footer displaying ea
export default {
data() {
return {
- tableData: [{
- id: '12987122',
- name: 'Tom',
- amount1: '234',
- amount2: '3.2',
- amount3: 10
- }, {
- id: '12987123',
- name: 'Tom',
- amount1: '165',
- amount2: '4.43',
- amount3: 12
- }, {
- id: '12987124',
- name: 'Tom',
- amount1: '324',
- amount2: '1.9',
- amount3: 9
- }, {
- id: '12987125',
- name: 'Tom',
- amount1: '621',
- amount2: '2.2',
- amount3: 17
- }, {
- id: '12987126',
- name: 'Tom',
- amount1: '539',
- amount2: '4.1',
- amount3: 15
- }]
- };
+ tableData: [
+ {
+ id: '12987122',
+ name: 'Tom',
+ amount1: '234',
+ amount2: '3.2',
+ amount3: 10,
+ },
+ {
+ id: '12987123',
+ name: 'Tom',
+ amount1: '165',
+ amount2: '4.43',
+ amount3: 12,
+ },
+ {
+ id: '12987124',
+ name: 'Tom',
+ amount1: '324',
+ amount2: '1.9',
+ amount3: 9,
+ },
+ {
+ id: '12987125',
+ name: 'Tom',
+ amount1: '621',
+ amount2: '2.2',
+ amount3: 17,
+ },
+ {
+ id: '12987126',
+ name: 'Tom',
+ amount1: '539',
+ amount2: '4.1',
+ amount3: 15,
+ },
+ ],
+ }
},
methods: {
getSummaries(param) {
- const { columns, data } = param;
- const sums = [];
+ const { columns, data } = param
+ const sums = []
columns.forEach((column, index) => {
if (index === 0) {
- sums[index] = 'Total Cost';
- return;
+ sums[index] = 'Total Cost'
+ return
}
- const values = data.map(item => Number(item[column.property]));
+ const values = data.map(item => Number(item[column.property]))
if (!values.every(value => isNaN(value))) {
- sums[index] = '$ ' + values.reduce((prev, curr) => {
- const value = Number(curr);
- if (!isNaN(value)) {
- return prev + curr;
- } else {
- return prev;
- }
- }, 0);
+ sums[index] =
+ '$ ' +
+ values.reduce((prev, curr) => {
+ const value = Number(curr)
+ if (!isNaN(value)) {
+ return prev + curr
+ } else {
+ return prev
+ }
+ }, 0)
} else {
- sums[index] = 'N/A';
+ sums[index] = 'N/A'
}
- });
+ })
- return sums;
- }
- }
- };
+ return sums
+ },
+ },
+ }
```
+
:::
### Rowspan and colspan
@@ -1603,30 +1486,15 @@ Configuring rowspan and colspan allows you to merge cells
:data="tableData"
:span-method="arraySpanMethod"
border
- style="width: 100%">
-
+ style="width: 100%"
+ >
+
+
+
-
+
-
-
-
-
-
+
@@ -1634,28 +1502,13 @@ Configuring rowspan and colspan allows you to merge cells
:data="tableData"
:span-method="objectSpanMethod"
border
- style="width: 100%; margin-top: 20px">
-
-
-
-
-
-
-
-
-
-
+ style="width: 100%; margin-top: 20px"
+ >
+
+
+
+
+