/[projects]/misc/horsensspejder-web/jquery/DataTables-1.9.4/examples/server_side/pipeline.html
ViewVC logotype

Contents of /misc/horsensspejder-web/jquery/DataTables-1.9.4/examples/server_side/pipeline.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2125 - (show annotations) (download) (as text)
Wed Mar 12 19:30:05 2014 UTC (10 years, 2 months ago) by torben
File MIME type: text/html
File size: 17080 byte(s)
initial import
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" />
6
7 <title>DataTables example</title>
8 <style type="text/css" title="currentStyle">
9 @import "../../media/css/demo_page.css";
10 @import "../../media/css/demo_table.css";
11 </style>
12 <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
13 <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
14 <script type="text/javascript" charset="utf-8">
15 var oCache = {
16 iCacheLower: -1
17 };
18
19 function fnSetKey( aoData, sKey, mValue )
20 {
21 for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
22 {
23 if ( aoData[i].name == sKey )
24 {
25 aoData[i].value = mValue;
26 }
27 }
28 }
29
30 function fnGetKey( aoData, sKey )
31 {
32 for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
33 {
34 if ( aoData[i].name == sKey )
35 {
36 return aoData[i].value;
37 }
38 }
39 return null;
40 }
41
42 function fnDataTablesPipeline ( sSource, aoData, fnCallback, oSettings ) {
43 var iPipe = 5; /* Ajust the pipe size */
44
45 var bNeedServer = false;
46 var sEcho = fnGetKey(aoData, "sEcho");
47 var iRequestStart = fnGetKey(aoData, "iDisplayStart");
48 var iRequestLength = fnGetKey(aoData, "iDisplayLength");
49 var iRequestEnd = iRequestStart + iRequestLength;
50 oCache.iDisplayStart = iRequestStart;
51
52 /* outside pipeline? */
53 if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
54 {
55 bNeedServer = true;
56 }
57
58 /* sorting etc changed? */
59 if ( oCache.lastRequest && !bNeedServer )
60 {
61 for( var i=0, iLen=aoData.length ; i<iLen ; i++ )
62 {
63 if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" )
64 {
65 if ( aoData[i].value != oCache.lastRequest[i].value )
66 {
67 bNeedServer = true;
68 break;
69 }
70 }
71 }
72 }
73
74 /* Store the request for checking next time around */
75 oCache.lastRequest = aoData.slice();
76
77 if ( bNeedServer )
78 {
79 if ( iRequestStart < oCache.iCacheLower )
80 {
81 iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
82 if ( iRequestStart < 0 )
83 {
84 iRequestStart = 0;
85 }
86 }
87
88 oCache.iCacheLower = iRequestStart;
89 oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
90 oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
91 fnSetKey( aoData, "iDisplayStart", iRequestStart );
92 fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
93
94 oSettings.jqXHR = $.getJSON( sSource, aoData, function (json) {
95 /* Callback processing */
96 oCache.lastJson = jQuery.extend(true, {}, json);
97
98 if ( oCache.iCacheLower != oCache.iDisplayStart )
99 {
100 json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
101 }
102 json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
103
104 fnCallback(json)
105 } );
106 }
107 else
108 {
109 json = jQuery.extend(true, {}, oCache.lastJson);
110 json.sEcho = sEcho; /* Update the echo for each response */
111 json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
112 json.aaData.splice( iRequestLength, json.aaData.length );
113 fnCallback(json);
114 return;
115 }
116 }
117
118 $(document).ready(function() {
119 $('#example').dataTable( {
120 "bProcessing": true,
121 "bServerSide": true,
122 "sAjaxSource": "scripts/server_processing.php",
123 "fnServerData": fnDataTablesPipeline
124 } );
125 } );
126 </script>
127 </head>
128 <body id="dt_example">
129 <div id="container">
130 <div class="full_width big">
131 DataTables server-side processing with pipelining example
132 </div>
133
134 <h1>Preamble</h1>
135 <p>When using server-side processing with DataTables, it can be quite intensive on your server having an Ajax call every time the user performs some kind of interaction - you can effectively DDOS your server with your own application!</p>
136 <p>This example shows how you might over-come this by modifying the request set to the server to retrieve more information than is actually required for a single page's display. This means that the user can page multiple times (5 times the display size is the default) before a request must be made of the server. Paging is typically the most common interaction performed with a DataTable, so this can be most beneficial to your server's resource usage. Of course the pipeline must be cleared for interactions other than paging (sorting, filtering etc), but that's the trade off that can be made (sending extra information is cheap - while another XHR is expensive).</p>
137
138 <h1>Live example</h1>
139 <div id="dynamic">
140 <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
141 <thead>
142 <tr>
143 <th width="20%">Rendering engine</th>
144 <th width="25%">Browser</th>
145 <th width="25%">Platform(s)</th>
146 <th width="15%">Engine version</th>
147 <th width="15%">CSS grade</th>
148 </tr>
149 </thead>
150 <tbody>
151 <tr>
152 <td colspan="5" class="dataTables_empty">Loading data from server</td>
153 </tr>
154 </tbody>
155 <tfoot>
156 <tr>
157 <th>Rendering engine</th>
158 <th>Browser</th>
159 <th>Platform(s)</th>
160 <th>Engine version</th>
161 <th>CSS grade</th>
162 </tr>
163 </tfoot>
164 </table>
165 </div>
166 <div class="spacer"></div>
167
168
169 <h1>Initialisation code</h1>
170 <pre class="brush: js;">var oCache = {
171 iCacheLower: -1
172 };
173
174 function fnSetKey( aoData, sKey, mValue )
175 {
176 for ( var i=0, iLen=aoData.length ; i&lt;iLen ; i++ )
177 {
178 if ( aoData[i].name == sKey )
179 {
180 aoData[i].value = mValue;
181 }
182 }
183 }
184
185 function fnGetKey( aoData, sKey )
186 {
187 for ( var i=0, iLen=aoData.length ; i&lt;iLen ; i++ )
188 {
189 if ( aoData[i].name == sKey )
190 {
191 return aoData[i].value;
192 }
193 }
194 return null;
195 }
196
197 function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
198 var iPipe = 5; /* Ajust the pipe size */
199
200 var bNeedServer = false;
201 var sEcho = fnGetKey(aoData, "sEcho");
202 var iRequestStart = fnGetKey(aoData, "iDisplayStart");
203 var iRequestLength = fnGetKey(aoData, "iDisplayLength");
204 var iRequestEnd = iRequestStart + iRequestLength;
205 oCache.iDisplayStart = iRequestStart;
206
207 /* outside pipeline? */
208 if ( oCache.iCacheLower &lt; 0 || iRequestStart &lt; oCache.iCacheLower || iRequestEnd &gt; oCache.iCacheUpper )
209 {
210 bNeedServer = true;
211 }
212
213 /* sorting etc changed? */
214 if ( oCache.lastRequest &amp;&amp; !bNeedServer )
215 {
216 for( var i=0, iLen=aoData.length ; i&lt;iLen ; i++ )
217 {
218 if ( aoData[i].name != "iDisplayStart" &amp;&amp; aoData[i].name != "iDisplayLength" &amp;&amp; aoData[i].name != "sEcho" )
219 {
220 if ( aoData[i].value != oCache.lastRequest[i].value )
221 {
222 bNeedServer = true;
223 break;
224 }
225 }
226 }
227 }
228
229 /* Store the request for checking next time around */
230 oCache.lastRequest = aoData.slice();
231
232 if ( bNeedServer )
233 {
234 if ( iRequestStart &lt; oCache.iCacheLower )
235 {
236 iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
237 if ( iRequestStart &lt; 0 )
238 {
239 iRequestStart = 0;
240 }
241 }
242
243 oCache.iCacheLower = iRequestStart;
244 oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
245 oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
246 fnSetKey( aoData, "iDisplayStart", iRequestStart );
247 fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
248
249 $.getJSON( sSource, aoData, function (json) {
250 /* Callback processing */
251 oCache.lastJson = jQuery.extend(true, {}, json);
252
253 if ( oCache.iCacheLower != oCache.iDisplayStart )
254 {
255 json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
256 }
257 json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
258
259 fnCallback(json)
260 } );
261 }
262 else
263 {
264 json = jQuery.extend(true, {}, oCache.lastJson);
265 json.sEcho = sEcho; /* Update the echo for each response */
266 json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
267 json.aaData.splice( iRequestLength, json.aaData.length );
268 fnCallback(json);
269 return;
270 }
271 }
272
273 $(document).ready(function() {
274 $('#example').dataTable( {
275 "bProcessing": true,
276 "bServerSide": true,
277 "sAjaxSource": "scripts/server_processing.php",
278 "fnServerData": fnDataTablesPipeline
279 } );
280 } );</pre>
281 <style type="text/css">
282 @import "../examples_support/syntax/css/shCore.css";
283 </style>
284 <script type="text/javascript" language="javascript" src="../examples_support/syntax/js/shCore.js"></script>
285
286 <h1>Server response</h1>
287 <p>The code below shows the latest JSON data that has been returned from the server in response to the Ajax request made by DataTables. This will update as further requests are made.</p>
288 <pre id="latest_xhr" class="brush: js;"></pre>
289
290
291 <h1>Other examples</h1>
292 <div class="demo_links">
293 <h2>Basic initialisation</h2>
294 <ul>
295 <li><a href="../basic_init/zero_config.html">Zero configuration</a></li>
296 <li><a href="../basic_init/filter_only.html">Feature enablement</a></li>
297 <li><a href="../basic_init/table_sorting.html">Sorting data</a></li>
298 <li><a href="../basic_init/multi_col_sort.html">Multi-column sorting</a></li>
299 <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
300 <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
301 <li><a href="../basic_init/complex_header.html">Complex headers - grouping with colspan</a></li>
302 <li><a href="../basic_init/dom.html">DOM positioning</a></li>
303 <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li>
304 <li><a href="../basic_init/state_save.html">State saving</a></li>
305 <li><a href="../basic_init/alt_pagination.html">Alternative pagination styles</a></li>
306 <li>Scrolling: <br>
307 <a href="../basic_init/scroll_x.html">Horizontal</a> /
308 <a href="../basic_init/scroll_y.html">Vertical</a> /
309 <a href="../basic_init/scroll_xy.html">Both</a> /
310 <a href="../basic_init/scroll_y_theme.html">Themed</a> /
311 <a href="../basic_init/scroll_y_infinite.html">Infinite</a>
312 </li>
313 <li><a href="../basic_init/language.html">Change language information (internationalisation)</a></li>
314 <li><a href="../basic_init/themes.html">ThemeRoller themes (Smoothness)</a></li>
315 </ul>
316
317 <h2>Advanced initialisation</h2>
318 <ul>
319 <li>Events: <br>
320 <a href="../advanced_init/events_live.html">Live events</a> /
321 <a href="../advanced_init/events_pre_init.html">Pre-init</a> /
322 <a href="../advanced_init/events_post_init.html">Post-init</a>
323 </li>
324 <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
325 <li><a href="../advanced_init/html_sort.html">Sorting without HTML tags</a></li>
326 <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table controls (sDom)</a></li>
327 <li><a href="../advanced_init/length_menu.html">Defining length menu options</a></li>
328 <li><a href="../advanced_init/complex_header.html">Complex headers and hidden columns</a></li>
329 <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar (element) around table</a></li>
330 <li><a href="../advanced_init/highlight.html">Row highlighting with CSS</a></li>
331 <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
332 <li><a href="../advanced_init/row_callback.html">Row callback</a></li>
333 <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
334 <li><a href="../advanced_init/sorting_control.html">Control sorting direction of columns</a></li>
335 <li><a href="../advanced_init/language_file.html">Change language information from a file (internationalisation)</a></li>
336 <li><a href="../advanced_init/defaults.html">Setting defaults</a></li>
337 <li><a href="../advanced_init/localstorage.html">State saving with localStorage</a></li>
338 <li><a href="../advanced_init/dt_events.html">Custom events</a></li>
339 </ul>
340
341 <h2>API</h2>
342 <ul>
343 <li><a href="../api/add_row.html">Dynamically add a new row</a></li>
344 <li><a href="../api/multi_filter.html">Individual column filtering (using "input" elements)</a></li>
345 <li><a href="../api/multi_filter_select.html">Individual column filtering (using "select" elements)</a></li>
346 <li><a href="../api/highlight.html">Highlight rows and columns</a></li>
347 <li><a href="../api/row_details.html">Show and hide details about a particular record</a></li>
348 <li><a href="../api/select_row.html">User selectable rows (multiple rows)</a></li>
349 <li><a href="../api/select_single_row.html">User selectable rows (single row) and delete rows</a></li>
350 <li><a href="../api/editable.html">Editable rows (with jEditable)</a></li>
351 <li><a href="../api/form.html">Submit form with elements in table</a></li>
352 <li><a href="../api/counter_column.html">Index column (static number column)</a></li>
353 <li><a href="../api/show_hide.html">Show and hide columns dynamically</a></li>
354 <li><a href="../api/api_in_init.html">API function use in initialisation object (callback)</a></li>
355 <li><a href="../api/tabs_and_scrolling.html">DataTables scrolling and tabs</a></li>
356 <li><a href="../api/regex.html">Regular expression filtering</a></li>
357 </ul>
358 </div>
359
360 <div class="demo_links">
361 <h2>Data sources</h2>
362 <ul>
363 <li><a href="../data_sources/dom.html">DOM</a></li>
364 <li><a href="../data_sources/js_array.html">Javascript array</a></li>
365 <li><a href="../data_sources/ajax.html">Ajax source</a></li>
366 <li><a href="../data_sources/server_side.html">Server side processing</a></li>
367 </ul>
368
369 <h2>Server-side processing</h2>
370 <ul>
371 <li><a href="../server_side/server_side.html">Obtain server-side data</a></li>
372 <li><a href="../server_side/custom_vars.html">Add extra HTTP variables</a></li>
373 <li><a href="../server_side/post.html">Use HTTP POST</a></li>
374 <li><a href="../server_side/ids.html">Automatic addition of IDs and classes to rows</a></li>
375 <li><a href="../server_side/object_data.html">Reading table data from objects</a></li>
376 <li><a href="../server_side/row_details.html">Show and hide details about a particular record</a></li>
377 <li><a href="../server_side/select_rows.html">User selectable rows (multiple rows)</a></li>
378 <li><a href="../server_side/jsonp.html">JSONP for a cross domain data source</a></li>
379 <li><a href="../server_side/editable.html">jEditable integration with DataTables</a></li>
380 <li><a href="../server_side/defer_loading.html">Deferred loading of Ajax data</a></li>
381 <li><a href="../server_side/pipeline.html">Pipelining data (reduce Ajax calls for paging)</a></li>
382 </ul>
383
384 <h2>Ajax data source</h2>
385 <ul>
386 <li><a href="../ajax/ajax.html">Ajax sourced data (array of arrays)</a></li>
387 <li><a href="../ajax/objects.html">Ajax sourced data (array of objects)</a></li>
388 <li><a href="../ajax/defer_render.html">Deferred DOM creation for extra speed</a></li>
389 <li><a href="../ajax/null_data_source.html">Empty data source columns</a></li>
390 <li><a href="../ajax/custom_data_property.html">Use a data source other than aaData (the default)</a></li>
391 <li><a href="../ajax/objects_subarrays.html">Read column data from sub-arrays</a></li>
392 <li><a href="../ajax/deep.html">Read column data from deeply nested properties</a></li>
393 </ul>
394
395 <h2>Plug-ins</h2>
396 <ul>
397 <li><a href="../plug-ins/plugin_api.html">Add custom API functions</a></li>
398 <li><a href="../plug-ins/sorting_plugin.html">Sorting and automatic type detection</a></li>
399 <li><a href="../plug-ins/sorting_sType.html">Sorting without automatic type detection</a></li>
400 <li><a href="../plug-ins/paging_plugin.html">Custom pagination controls</a></li>
401 <li><a href="../plug-ins/range_filtering.html">Range filtering / custom filtering</a></li>
402 <li><a href="../plug-ins/dom_sort.html">Live DOM sorting</a></li>
403 <li><a href="../plug-ins/html_sort.html">Automatic HTML type detection</a></li>
404 </ul>
405 </div>
406
407
408 <div id="footer" class="clear" style="text-align:center;">
409 <p>
410 Please refer to the <a href="http://www.datatables.net/usage">DataTables documentation</a> for full information about its API properties and methods.<br>
411 Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of DataTables.
412 </p>
413
414 <span style="font-size:10px;">
415 DataTables designed and created by <a href="http://www.sprymedia.co.uk">Allan Jardine</a> &copy; 2007-2011<br>
416 DataTables is dual licensed under the <a href="http://www.datatables.net/license_gpl2">GPL v2 license</a> or a <a href="http://www.datatables.net/license_bsd">BSD (3-point) license</a>.
417 </span>
418 </div>
419 </div>
420 </body>
421 </html>

  ViewVC Help
Powered by ViewVC 1.1.20