group
Gets or sets the grouping configuration.
Parameters
value Object|Array
The grouping configuration. Accepts the same values as the group option.
Returns
Array
—The current grouping configuration.
Example - group the data items
<script>
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Tea", category: "Beverages" },
{ name: "Coffee", category: "Beverages" },
{ name: "Ham", category: "Food" }
]
});
dataSource.group({ field: "category" });
var view = dataSource.view();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(view.length); // displays "2"
var beverages = view[0];
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(beverages.value); // displays "Beverages"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(beverages.items[0].name); // displays "Tea"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(beverages.items[1].name); // displays "Coffee"
var food = view[1];
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(food.value); // displays "Food"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(food.items[0].name); // displays "Ham"
</script>
Example - get the data source grouping configuration
<script>
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Tea", category: "Beverages" },
{ name: "Coffee", category: "Beverages" },
{ name: "Ham", category: "Food" }
],
group: { field: "category" }
});
var groups = dataSource.group();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(groups.length); // displays "1"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(groups[0].field); // displays "category"
</script>