Vue List - Expand and Collapse a Group
If the user should be able to collapse or expand a group in the List, set the collapsibleGroups property to true. In this case, the user can collapse or expand a group with a click on the group header.
App.vue
- <template>
- <DxList
- :data-source="fruitsVegetables"
- :grouped="true"
- :collapsible-groups="true"
- />
- </template>
- <script>
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import DxList from 'devextreme-vue/list';
- const fruitsVegetables = [{
- key: "Fruits",
- items: [
- { name: "Apples", count: 10 },
- { name: "Oranges", count: 12 },
- { name: "Lemons", count: 15 }
- ]
- }, {
- // ...
- }];
- export default {
- components: {
- DxList
- },
- data() {
- return {
- fruitsVegetables
- }
- }
- }
- </script>
To collapse or expand a specific group programmatically, call the collapseGroup(groupIndex) or expandGroup(groupIndex) method.
App.vue
- <template>
- <DxList ...
- :ref="listRefKey"
- />
- </template>
- <script>
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import DxList from 'devextreme-vue/list';
- const listRefKey = "my-list";
- // ...
- export default {
- components: {
- DxList
- },
- data() {
- return {
- // ...
- listRefKey
- }
- },
- methods: {
- collapseGroup(groupIndex) {
- this.list.collapseGroup(groupIndex);
- },
- expandGroup(groupIndex) {
- this.list.expandGroup(groupIndex);
- }
- },
- computed: {
- list: function() {
- return this.$refs[listRefKey].instance;
- }
- }
- }
- </script>