FlexGrid Grouping
Object - FlexGrid Properties: - Grouping - Country and Product text filtering - FlexGrid filtering
by Joel Parks
HTML
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.grouppanel.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>
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-search"></span></div>
<input id="countryFilter" class="form-control" placeholder="Country Filter">
</div><br />
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-search"></span></div>
<input id="productFilter" class="form-control" placeholder="Product Filter">
</div><br />
<div id="theGrid">
</div>
<p>
You may also want to hide the columns that are being grouped
on in order to avoid showing redundant data.</p>
<p>
This example groups the data by country and product, and
hides those columns to achieve a cleaner appearance:</p>
<div id="theGridHideCols">
</div>
</div>
CSS
.wj-flexgrid {
max-height: 250px;
margin:10px 0;
}
body {
margin-bottom: 20px;
}
JavaScript
onload = function(){
// Creates two lists and an array to hold the items in the lists
var countries = 'US,Germany,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
});
}
// Grouping with nothing else attached to it
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
autoGenerateColumns: false,
columns: [{
binding: "id",
header: "ID",
// Can change the width by just modifying the 'width' tag (not sure if this is in pixels, assuming it is)
width: 75
}, {
binding: "country",
header: "COUNTRY",
// StarWidth expands/contracts a field so that the FlexGrid isn't too wide/narrow
width: 300
}, {
binding: "product",
header: "PRODUCT",
}, {
binding: "downloads",
header: "DOWNLOADS",
}, {
binding: "sales",
header: "SALES"
}, {
binding: "expenses",
header: "EXPENSES"
}],
itemsSource: new wijmo.collections.CollectionView(data, {
sortDescriptions: ['country', 'product'],
groupDescriptions: ['country', 'product'],
})
});
// Allows the user to filter by country name through the search bar
document.getElementById('countryFilter').addEventListener('input', function(e){
var countryFilter = e.target.value.toLowerCase();
theGrid.collectionView.filter = function(item){
return countryFilter.length == 0 || item.country.toLowerCase().indexOf(countryFilter) > -1
}
});
// Allows the user to filter by product name through the search bar
document.getElementById('productFilter').addEventListener('input', function(e){
var productFilter =...