FlexGrid - Getting Started
Simple JS implementation
by Troy Taylor
HTML
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<h1>
FlexGrid
</h1>
<p>
Each time the button is clicked, a new random data source is created with 5 more items.
</p>
<button id="switchData" onclick="switchDataSource()">
Switch Data Source
</button>
<div id="flexgrid"></div>
CSS
.wj-flexgrid {
height: 300px;
}
JavaScript
var flexgrid = new wijmo.grid.FlexGrid("#flexgrid");
var count = 5;
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [],
data2 = [];
for (var i = 0; i < count; i++) {
data.push({
id: i,
country: countries[i % countries.length],
active: i % 5 != 0,
downloads: Math.round(Math.random() * 200000),
sales: Math.random() * 100000,
expenses: Math.random() * 50000
});
}
flexgrid.itemsSource = data;
function switchDataSource() {
count += 5;
var oldData = flexgrid.collectionView.items;
var newData = [];
//oldData
console.log(flexgrid.collectionView.items);
for (var i = 0; i < count; i++) {
newData.push({
id: i,
country: countries[i % countries.length],
active: i % 5 != 0,
downloads: Math.round(Math.random() * 200000),
sales: Math.random() * 100000,
expenses: Math.random() * 50000
});
}
flexgrid.itemsSource = newData;
// newData
console.log(flexgrid.collectionView.items);
}