Demo - OData and Virtual Data
HTML
<link rel="stylesheet" href="https://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>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.odata.min.js"></script>
<div class="container">
<h1>
OData and Virtual Data</h1>
<p>
The <b>ODataCollectionView</b> class provides a
simple way to connect controls to OData sources.
When you create an <b>ODataCollectionView</b>,
it starts loading the data in the source.</p>
<p>
The <b>ODataVirtualCollectionView</b> extends
<b>ODataCollectionView</b> to provide <b>on-demand</b>
loading of data. It does not load the data from
the server automatically. Instead, it relies on the
<b>setWindow</b> method to load data fragments (windows)
on demand.</p>
<p>
The grids below show how both classes work. Notice how
the grid on the left shows the data being loaded gradually.
The grid on the right shows the full record count
immediately, but the data will not be loaded until you
scroll down.</p>
<div class="row">
<div class="col-sm-6">
<h4>
ODataCollectionView</h4>
<div id="itemCount"></div>
<div id="theGrid"></div>
</div>
<div class="col-sm-6">
<h4>
ODataVirtualCollectionView</h4>
<div id="totalItemCount"></div>
<div id="theVirtualGrid"></div>
</div>
</div>
</div>
CSS
.wj-flexgrid {
height: 300px;
}
.wj-flexgrid .wj-rowheaders .wj-cell {
font-size: 80%;
padding-top: .5em;
}
body {
margin-bottom: 20pt;
}
JavaScript
onload = function() {
// get order details into an ODataCollectionView
var url = 'https://services.odata.org/Northwind/Northwind.svc';
var table = 'Order_Details_Extendeds';
var orderDetails = new wijmo.odata.ODataCollectionView(url, table);
// show the data on a grid
var itemCountElement = document.getElementById('itemCount');
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
itemsSource: orderDetails, // ODataCollectionView
isReadOnly: true, // this service is read-only
formatItem: function(s, e) { // show row indices in row headers
if (e.panel.cellType == wijmo.grid.CellType.RowHeader) {
e.cell.textContent = e.row + 1;
}
},
loadedRows: function(sender, e) {
var el = document.getElementById('itemCount');
el.innerHTML = wijmo.format('{length:n0} items', sender.rows);
}
});
// get order details into a ODataVirtualCollectionView
var virtualDetails = new wijmo.odata.ODataVirtualCollectionView(url, table, {
loaded: function(sender, e) {
var el = document.getElementById('totalItemCount');
el.innerHTML = wijmo.format('{totalItemCount:n0} items', sender);
}
});
// show the data on a grid
var theVirtualGrid = new wijmo.grid.FlexGrid('#theVirtualGrid', {
itemsSource: virtualDetails, // ODataVirtualCollectionView
isReadOnly: true, // this service is read-only
formatItem: function(s, e) { // show row indices in row headers
if (e.panel.cellType == wijmo.grid.CellType.RowHeader) {
e.cell.textContent = e.row + 1;
}
},
scrollPositionChanged: function () {
var rng = theVirtualGrid.viewRange;
virtualDetails.setWindow(rng.row, rng.row2);
}
});
}