Grouping Basics

The native Vue Grid by Kendo UI enables you to display grouped table data.

Getting Started

To enable grouping:

  1. Set the groupable and group options of the Grid.
  2. Handle the onGroupChange or the emitted onDataStateChange event.
  3. Manually group the data.
<div id="vueapp" class="vue-app">
    <Grid ref="grid"
          :style="{height: '520px'}"
          :data-items="gridData"
          :resizable="true"
          :reorderable="true"
          :sortable="true"
          :pageable="gridPageable"
          :groupable="true"
          :group= "group"
          :take="take"
          :skip="skip"
          :expand-field="'expanded'"
          :columns="columns"
          @dataStateChange="dataStateChange"
          @expandchange="expandChange">
    </Grid>
</div>
import { process } from '@progress/kendo-data-query';
import { Grid } from '@progress/kendo-vue-grid';

Vue.component('Grid', Grid);

new Vue({
    el: '#vueapp',
    data: function () {
        return {
            gridPageable: { pageSizes: true },
            products: this.createRandomData(1000),
            gridData: [],
            skip: 0,
            take: 10,
            group: [ { field: 'UnitsInStock' } ],
            expandedItems: [],
            columns: [
                { field: 'ProductID', filterable: false, title: 'ID', width: '50px' },
                { field: 'ProductName', title: 'Product Name' },
                { field: 'UnitPrice', filter: 'numeric', title: 'Unit Price' },
                { field: 'UnitsInStock', title: 'Units In Stock' }
            ]
        };
    },
    created: function() {
        this.getData();
    },
    methods: {
        getData: function () {
            this.gridData = process(this.products, {take: this.take, skip: this.skip, group: this.group});
        },
        createAppState: function(dataState) {
            this.group = dataState.group;
            this.take = dataState.take;
            this.skip = dataState.skip;
            this.getData();
        },
        dataStateChange: function (event) {
            this.createAppState(event.data);
        },
        expandChange: function (event) {
            Vue.set(event.dataItem, event.target.$props.expandField, event.value);
        },
        createRandomData(count) {
            const productNames = ['Chai', 'Chang', 'Syrup', 'Apple', 'Orange', 'Banana', 'Lemon', 'Pineapple', 'Tea', 'Milk'];
            const unitPrices = [12.5, 10.1, 5.3, 7, 22.53, 16.22, 20, 50, 100, 120];
            const units = [2, 7, 12, 25,  67, 233, 123, 53, 67, 89];

            return Array(count).fill({}).map((_, idx) => ({
                ProductID: idx + 1,
                ProductName: productNames[Math.floor(Math.random() * productNames.length)],
                UnitPrice: unitPrices[Math.floor(Math.random() * unitPrices.length)],
                UnitsInStock: units[Math.floor(Math.random() * units.length)]
            }));
        }
    }
});

In this article