Grouping Basics
The Kendo UI Native DataGrid enables you to display grouped table data.
Enabling Grouping
The Kendo UI for Vue Grid supports grouping in two modes:
-
Built-in State Management: The Grid manages its own grouping state internally.
-
Controlled Mode: You manage the grouping state externally by handling events and updating the state.
Using the Built-in State Management for Grouping
To use grouping with the built-in state management, follow these steps:
-
Enable the
autoProcessDataprop to let the Grid handle grouping automatically. -
Set the
groupableprop of the Grid to enable grouping features. -
Set the
dataItemKeyprop to a unique value field from the data in the Grid. -
(Optional) Set the
defaultGroupprop to add initial grouping for the Grid.
<Grid :auto-process-data="true" :groupable="true" />
The following example shows how to use grouping with the built-in state management of the Kendo UI for Vue Grid.
Using the Grouping in Controlled Mode
To use grouping in the Kendo UI for Vue Grid with controlled mode, follow these steps:
- Set the
groupableandgroupprops of the Grid. - Handle the
groupchangeordatastatechangeevent. Usedatastatechangewhen the Grid has other data operations because it provides the completeStateobject in one event. - Group data on the client with
groupByorprocess. You can also group data on the server by using the event parameters. Provide the Grid with a collection ofGroupResultitems.
Use
groupBywithgroupchange, and useprocesswithdatastatechange.
For more information, see the Data Query process helpers documentation.
The following example shows how to use grouping in controlled mode where you manage the grouping state by handling events.
Grouping Columns Dynamically
By default, you can group all Grid columns multiple times. To enable grouping for specific columns and control it dynamically, use a function or variable for the groupable property.
<Grid :columns="[
{ field: 'ProductID', filterable: false, title: 'ID', width: '50px', groupable: isGroupable('ProductID') }
]" />
<script setup lang="ts">
import { ref, computed } from 'vue';
import type { GroupDescriptor } from '@progress/kendo-data-query';
const group = ref<GroupDescriptor[]>(initialGroup);
const isGroupable = (field: string) => {
return !((group.value || []).find((groupDescriptor) => groupDescriptor.field === field));
};
</script>
Persist Groups Collapsed State
The Data Tools setGroupIds utility creates unique group item IDs. Use these IDs with the groupExpand state to preserve the expanded or collapsed state of grouped items.
The following example demonstrates how to preserve the expanded and collapsed state of grouped items while the processed data changes. It uses setGroupIds from Data Tools, groupBy from Data Query, and a ref for the groupExpand state.
Expand and Collapse All Groups
Store group expansion state in the groupExpand prop. To collapse all groups, set expanded to false in the descriptors for each group. To restore the default expanded state, clear the groupExpand descriptors.
The following example demonstrates how to expand and collapse all group items by clicking a toggle button. It updates the groupExpand descriptors for every visible group.