forked from vpllan/jQuery.dataTables.oData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ODataProductsV2.html
195 lines (171 loc) · 6.38 KB
/
ODataProductsV2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" type="image/ico" href="http://www.sprymedia.co.uk/media/images/favicon.ico">
<title>Using dataTable with OData connector</title>
<style type="text/css" title="currentStyle">
@import "media/css/demo_page.css";
@import "media/css/demo_table.css";
@import "media/css/themes/base/jquery-ui.css";
@import "media/css/themes/smoothness/jquery-ui-1.7.2.custom.css";
</style>
<script src="media/js/jquery.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.odata.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
$('#products1').dataTable({
"sPaginationType": "full_numbers",
"aLengthMenu": [[2, 5, 10, -1], ["Two", "Five", "Ten", "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://services.odata.org/V2/OData/OData.svc/Products",
"aoColumns": [
{ mData: "Name" },
{ mData: "Description" },
{ mData: "Rating", sType: 'numeric' },
{ mData: "Price", sType: 'numeric' },
{ sName: "ReleaseDate", sType: 'date',
mData: function(source, type, val) {
if (source.ReleaseDate.indexOf("/Date") > -1) {
var temp = source.ReleaseDate.substring(6, source.ReleaseDate.length - 2);
return new Date(Number(temp));
}
return source.ReleaseDate;
}
}
],
"fnServerData": fnServerOData,
"iODataVersion": 2,
"bUseODataViaJSONP": true
});
$('#products2').dataTable({
"sPaginationType": "full_numbers",
"aLengthMenu": [[2, 5, 10, -1], ["Two", "Five", "Ten", "All"]],
"bProcessing": true,
"bServerSide": false,
"sAjaxSource": "http://services.odata.org/V2/OData/OData.svc/Products",
"aoColumns": [
{ mData: "Name" },
{ mData: "Description" },
{ mData: "Rating", sType: 'numeric' },
{ mData: "Price", sType: 'numeric' },
{ sName: "ReleaseDate", sType: 'date',
mData: function(source, type, val) {
if (source.ReleaseDate.indexOf("/Date") > -1) {
var temp = source.ReleaseDate.substring(6, source.ReleaseDate.length - 2);
return new Date(Number(temp));
}
return source.ReleaseDate;
}
}
],
"fnServerData": fnServerOData,
"iODataVersion": 2,
"bUseODataViaJSONP": true
});
} );
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17838786-4']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body id="dt_example">
<div id="container">
<a href="http://vpllan.github.io/jQuery.dataTables.oData/">Home</a>
<a href="https://github.com/vpllan/jQuery.dataTables.oData/wiki">Wiki</a>
<div class="full_width big">
JQuery DataTables OData
</div>
<h1>Preamble</h1>
<p>DataTables OData Integration.</p>
<h1>Live example</h1>
<div id="demo">
<h2>With OData Service as server-side processing logic</h2>
<p>Filtering on numeric/datetime columns does not work, because there is no efficient way to search by these types using OData URL query.
These columns should be marked as numeric or date with sType parameter in DataTable initialization in order to avoid exception that will be thrown
by OData service.</p>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="products1">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Rating</th>
<th>Price</th>
<th>Release date</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h2>With OData Service as Ajax source</h2>
<p>Fully functional table</p>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="products2">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Rating</th>
<th>Price</th>
<th>Release date</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="spacer"></div>
<h1>Initialization code</h1>
<p>Initialization code is very simple. Just specify "fnServerOData" value for "fnServerData" parameter, and define OData service version in "iODataVersion" parameter.</p>
<pre>
$(document).ready( function () {
$('#products1').dataTable({
"sPaginationType": "full_numbers",
"aLengthMenu": [[2, 5, 10, -1], ["Two", "Five", "Ten", "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://services.odata.org/V2/OData/OData.svc/Products",
"aoColumns": [
{ mData: "Name" },
{ mData: "Description" },
{ mData: "Rating", sType: 'numeric' },
{ mData: "Price", sType: 'numeric' },
{ sName: "ReleaseDate", sType: 'date',
mData: function(source, type, val) {
if (source.ReleaseDate.indexOf("/Date") > -1) {
var temp = source.ReleaseDate.substring(6, source.ReleaseDate.length - 2);
return new Date(Number(temp));
}
return source.ReleaseDate;
}
}
],
"fnServerData": fnServerOData,
"iODataVersion": 2,
"bUseODataViaJSONP": true
});
}
</pre>
<h1>Other examples</h1>
<ul>
<li><a href="ODataProductsV4.html">Example for OData v4</a></li>
<li><a href="ODataProductsV3.html">Example for OData v3</a></li>
<li><a href="ODataProductsV2.html">Example for OData v2</a></li>
</ul>
<div id="footer" style="text-align:center;">
<span style="font-size:10px;">
DataTables OData Add-on © Jovan & Vida Popovic 2014.<br>
DataTables designed and created by <a href="http://www.sprymedia.co.uk">Allan Jardine</a> © 2007-2014<br>
</span>
</div>
</div>
</body>
</html>