Demo - Grouping
Expand/Collapse GroupRow on MouseClick
by Manish Gupta
HTML
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.min.js"></script>
<div class="container">
<h1>
Grouping</h1>
<p>
The grid supports grouping via the source <b>CollectionView</b>.</p>
<p>
Group the data by one or more properties by adding <b>GroupDescription</b>
objects to the grid's <b>collectionView.groupDescriptions</b>.</p>
<p>
This example groups the data by country and by product:</p>
<p>
The GroupRow expand/collpase position may be changed by setting isCollapsed property to false/true.
</p>
<div id="theGrid">
</div>
</div>
CSS
.wj-flexgrid {
max-height: 250px;
margin:10px 0;
}
body {
margin-bottom: 20px;
}
JavaScript
onload = function () {
// generate some random data
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
products = 'Phones,Computers,Cameras,Stereos'.split(','),
data = [];
for (var i = 0; i < 200; i++) {
data.push({
id: i,
country: countries[i % countries.length],
product: products[i % products.length],
downloads: Math.round(100 + Math.random() * 10000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000,
});
}
// basic grouping
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
itemsSource: new wijmo.collections.CollectionView(data, {
sortDescriptions: [ 'country', 'product' ],
groupDescriptions: [ 'country', 'product' ]
})
});
theGrid.hostElement.addEventListener("click",function(e){
var ht=theGrid.hitTest(e);
if(!wijmo.hasClass(e.target, 'wj-elem-collapse')){
theGrid.rows[ht.row].isCollapsed=!theGrid.rows[ht.row].isCollapsed;
}
});
// select first item (after sorting/grouping)
theGrid.select(new wijmo.grid.CellRange(0,0), true);
}