Skip to content

Instantly share code, notes, and snippets.

@gokhantaskan
Last active December 25, 2020 19:35
Show Gist options
  • Save gokhantaskan/bb50a36de6f802fa7c9874772ed35921 to your computer and use it in GitHub Desktop.
Save gokhantaskan/bb50a36de6f802fa7c9874772ed35921 to your computer and use it in GitHub Desktop.
ElementUI Table with Collapse Option (Accordion Style)
<template>
<el-table
ref="table"
row-key="someKey"
@row-click="rowClick"
@expand-change="expandChange"
:data="data"
>
<el-table-column type="expand">
<template v-slot:default="{ row }">
...
</template>
</el-table-column>
</el-table>
</template>
<script lang="ts">
import { defineComponent } from "@vue/composition-api";
import { ElTable } from "element-ui/types/table";
export default defineComponent({
...
methods: {
rowClick(row: any) {
(this.$refs.table as ElTable).toggleRowExpansion(row);
this.$emit("selected", row);
},
expandChange(row: any, expanded: any[]) {
const rows = [...expanded];
if (rows.length > 1) {
rows.pop();
rows.forEach(row => (this.$refs.table as ElTable).toggleRowExpansion(row));
}
},
},
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment