Last active
December 25, 2020 19:35
-
-
Save gokhantaskan/bb50a36de6f802fa7c9874772ed35921 to your computer and use it in GitHub Desktop.
ElementUI Table with Collapse Option (Accordion Style)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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