Demo - Auto-Sizing
HTML
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://prerelease.componentone.com/wijmo5/latest/styles/wijmo.min.css">
<script src="http://prerelease.componentone.com/wijmo5/latest/controls/wijmo.min.js"></script>
<script src="http://prerelease.componentone.com/wijmo5/latest/controls/wijmo.input.min.js"></script>
<script src="http://prerelease.componentone.com/wijmo5/latest/controls/wijmo.grid.min.js"></script>
<div class="container">
<h1>
Auto-Sizing Performance</h1>
<p>
The FlexGrid has <b>autoSizeColumns</b> and <b>autoSizeRows</b>
methods you can call to automatically size rows and columns
to fit their content.</p>
<p>
With large datasets, these methods can be slow. This sample logs the performance of the functions (in milliseconds) and reports it in the console.</p>
<p>
Click this button to size the columns of the
grid below to fit their content:</p>
<button id="autoSizeColumns" class="btn byn-default">
autoSizeColumns
</button>
<label for="quickAutoSize">quickAutoSize</label>
<input id="quickAutoSize" type="checkbox" checked="checked">
<div id="theGrid"></div>
<div class="panel panel-warning">
<div class="panel-heading">
Automatically resizing rows and columns is one of the
most time-consuming grid operations. As of build 379, we have added an optimization that vastly improves performance for unformatted cells. This new feature is available by setting quickAutoSize=true.
</div>
</div>
</div>
CSS
.wj-flexgrid {
height: 400px;
margin:10px 0;
}
JavaScript
onload = function () {
// generate some random data
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < 20000; i++) {
data.push({
id: i,
country: countries[i % countries.length],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
quickAutoSize: true,
autoGenerateColumns: false,
columns:[
{ binding: 'id', header: 'ID', width: 60 },
{ binding: 'country', header: 'Country'},
{ binding: 'sales', header: 'Sales'},
{ binding: 'expenses', header: 'Expenses'}
],
itemsSource: data
});
document.getElementById('quickAutoSize').addEventListener('click', function(e) {
theGrid.quickAutoSize = e.target.checked;
})
// autosize when pressing button
document.getElementById('autoSizeColumns').addEventListener('click', function() {
console.time("autoSizeColumns, quickAutoSize=" + theGrid.quickAutoSize);
theGrid.autoSizeColumns();
console.timeEnd("autoSizeColumns, quickAutoSize=" + theGrid.quickAutoSize);
})
}