PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/worldbuilder/js/lib/datatables/examples/server_side/pipeline.html

https://github.com/backr3ap/Rhynn
HTML | 380 lines | 337 code | 43 blank | 0 comment | 0 complexity | 70f44cdb699663aadca518ea8baa20e4 MD5 | raw file
  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. <title>DataTables example</title>
  7. <style type="text/css" title="currentStyle">
  8. @import "../../media/css/demo_page.css";
  9. @import "../../media/css/demo_table.css";
  10. </style>
  11. <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
  12. <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
  13. <script type="text/javascript" charset="utf-8">
  14. var oCache = {
  15. iCacheLower: -1
  16. };
  17. function fnSetKey( aoData, sKey, mValue )
  18. {
  19. for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  20. {
  21. if ( aoData[i].name == sKey )
  22. {
  23. aoData[i].value = mValue;
  24. }
  25. }
  26. }
  27. function fnGetKey( aoData, sKey )
  28. {
  29. for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  30. {
  31. if ( aoData[i].name == sKey )
  32. {
  33. return aoData[i].value;
  34. }
  35. }
  36. return null;
  37. }
  38. function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
  39. var iPipe = 5; /* Ajust the pipe size */
  40. var bNeedServer = false;
  41. var sEcho = fnGetKey(aoData, "sEcho");
  42. var iRequestStart = fnGetKey(aoData, "iDisplayStart");
  43. var iRequestLength = fnGetKey(aoData, "iDisplayLength");
  44. var iRequestEnd = iRequestStart + iRequestLength;
  45. oCache.iDisplayStart = iRequestStart;
  46. /* outside pipeline? */
  47. if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
  48. {
  49. bNeedServer = true;
  50. }
  51. /* sorting etc changed? */
  52. if ( oCache.lastRequest && !bNeedServer )
  53. {
  54. for( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  55. {
  56. if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" )
  57. {
  58. if ( aoData[i].value != oCache.lastRequest[i].value )
  59. {
  60. bNeedServer = true;
  61. break;
  62. }
  63. }
  64. }
  65. }
  66. /* Store the request for checking next time around */
  67. oCache.lastRequest = aoData.slice();
  68. if ( bNeedServer )
  69. {
  70. if ( iRequestStart < oCache.iCacheLower )
  71. {
  72. iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
  73. if ( iRequestStart < 0 )
  74. {
  75. iRequestStart = 0;
  76. }
  77. }
  78. oCache.iCacheLower = iRequestStart;
  79. oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
  80. oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
  81. fnSetKey( aoData, "iDisplayStart", iRequestStart );
  82. fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
  83. $.getJSON( sSource, aoData, function (json) {
  84. /* Callback processing */
  85. oCache.lastJson = jQuery.extend(true, {}, json);
  86. if ( oCache.iCacheLower != oCache.iDisplayStart )
  87. {
  88. json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
  89. }
  90. json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
  91. fnCallback(json)
  92. } );
  93. }
  94. else
  95. {
  96. json = jQuery.extend(true, {}, oCache.lastJson);
  97. json.sEcho = sEcho; /* Update the echo for each response */
  98. json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
  99. json.aaData.splice( iRequestLength, json.aaData.length );
  100. fnCallback(json);
  101. return;
  102. }
  103. }
  104. $(document).ready(function() {
  105. $('#example').dataTable( {
  106. "bProcessing": true,
  107. "bServerSide": true,
  108. "sAjaxSource": "../examples_support/server_processing.php",
  109. "fnServerData": fnDataTablesPipeline
  110. } );
  111. } );
  112. </script>
  113. </head>
  114. <body id="dt_example">
  115. <div id="container">
  116. <div class="full_width big">
  117. <i>DataTables</i> server-side processing with pipelining example
  118. </div>
  119. <h1>Preamble</h1>
  120. <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>
  121. <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 cheep - while another XHR is expensive).</p>
  122. <h1>Live example</h1>
  123. <div id="dynamic">
  124. <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
  125. <thead>
  126. <tr>
  127. <th width="20%">Rendering engine</th>
  128. <th width="25%">Browser</th>
  129. <th width="25%">Platform(s)</th>
  130. <th width="15%">Engine version</th>
  131. <th width="15%">CSS grade</th>
  132. </tr>
  133. </thead>
  134. <tbody>
  135. <tr>
  136. <td colspan="5" class="dataTables_empty">Loading data from server</td>
  137. </tr>
  138. </tbody>
  139. <tfoot>
  140. <tr>
  141. <th>Rendering engine</th>
  142. <th>Browser</th>
  143. <th>Platform(s)</th>
  144. <th>Engine version</th>
  145. <th>CSS grade</th>
  146. </tr>
  147. </tfoot>
  148. </table>
  149. </div>
  150. <div class="spacer"></div>
  151. <h1>Initialisation code</h1>
  152. <pre>var oCache = {
  153. iCacheLower: -1
  154. };
  155. function fnSetKey( aoData, sKey, mValue )
  156. {
  157. for ( var i=0, iLen=aoData.length ; i&lt;iLen ; i++ )
  158. {
  159. if ( aoData[i].name == sKey )
  160. {
  161. aoData[i].value = mValue;
  162. }
  163. }
  164. }
  165. function fnGetKey( aoData, sKey )
  166. {
  167. for ( var i=0, iLen=aoData.length ; i&lt;iLen ; i++ )
  168. {
  169. if ( aoData[i].name == sKey )
  170. {
  171. return aoData[i].value;
  172. }
  173. }
  174. return null;
  175. }
  176. function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
  177. var iPipe = 5; /* Ajust the pipe size */
  178. var bNeedServer = false;
  179. var sEcho = fnGetKey(aoData, "sEcho");
  180. var iRequestStart = fnGetKey(aoData, "iDisplayStart");
  181. var iRequestLength = fnGetKey(aoData, "iDisplayLength");
  182. var iRequestEnd = iRequestStart + iRequestLength;
  183. oCache.iDisplayStart = iRequestStart;
  184. /* outside pipeline? */
  185. if ( oCache.iCacheLower &lt; 0 || iRequestStart &lt; oCache.iCacheLower || iRequestEnd &gt; oCache.iCacheUpper )
  186. {
  187. bNeedServer = true;
  188. }
  189. /* sorting etc changed? */
  190. if ( oCache.lastRequest &amp;&amp; !bNeedServer )
  191. {
  192. for( var i=0, iLen=aoData.length ; i&lt;iLen ; i++ )
  193. {
  194. if ( aoData[i].name != "iDisplayStart" &amp;&amp; aoData[i].name != "iDisplayLength" &amp;&amp; aoData[i].name != "sEcho" )
  195. {
  196. if ( aoData[i].value != oCache.lastRequest[i].value )
  197. {
  198. bNeedServer = true;
  199. break;
  200. }
  201. }
  202. }
  203. }
  204. /* Store the request for checking next time around */
  205. oCache.lastRequest = aoData.slice();
  206. if ( bNeedServer )
  207. {
  208. if ( iRequestStart &lt; oCache.iCacheLower )
  209. {
  210. iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
  211. if ( iRequestStart &lt; 0 )
  212. {
  213. iRequestStart = 0;
  214. }
  215. }
  216. oCache.iCacheLower = iRequestStart;
  217. oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
  218. oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
  219. fnSetKey( aoData, "iDisplayStart", iRequestStart );
  220. fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
  221. $.getJSON( sSource, aoData, function (json) {
  222. /* Callback processing */
  223. oCache.lastJson = jQuery.extend(true, {}, json);
  224. if ( oCache.iCacheLower != oCache.iDisplayStart )
  225. {
  226. json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
  227. }
  228. json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
  229. fnCallback(json)
  230. } );
  231. }
  232. else
  233. {
  234. json = jQuery.extend(true, {}, oCache.lastJson);
  235. json.sEcho = sEcho; /* Update the echo for each response */
  236. json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
  237. json.aaData.splice( iRequestLength, json.aaData.length );
  238. fnCallback(json);
  239. return;
  240. }
  241. }
  242. $(document).ready(function() {
  243. $('#example').dataTable( {
  244. "bProcessing": true,
  245. "bServerSide": true,
  246. "sAjaxSource": "../examples_support/server_processing.php",
  247. "fnServerData": fnDataTablesPipeline
  248. } );
  249. } );</pre>
  250. <h1>Other examples</h1>
  251. <h2>Basic initialisation</h2>
  252. <ul>
  253. <li><a href="../basic_init/zero_config.html">Zero configuration</a></li>
  254. <li><a href="../basic_init/filter_only.html">Feature enablement</a></li>
  255. <li><a href="../basic_init/table_sorting.html">Sorting data</a></li>
  256. <li><a href="../basic_init/multi_col_sort.html">Multi-column sorting</a></li>
  257. <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
  258. <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
  259. <li><a href="../basic_init/dom.html">DOM positioning</a></li>
  260. <li><a href="../basic_init/state_save.html">State saving</a></li>
  261. <li><a href="../basic_init/alt_pagination.html">Alternative pagination styles</a></li>
  262. <li>Scrolling:
  263. <a href="../basic_init/scroll_x.html">Horizontal</a> /
  264. <a href="../basic_init/scroll_y.html">Vertical</a> /
  265. <a href="../basic_init/scroll_xy.html">Both</a> /
  266. <a href="../basic_init/scroll_y_theme.html">Themed</a> /
  267. <a href="../basic_init/scroll_y_infinite.html">Infinite</a>
  268. </li>
  269. <li><a href="../basic_init/language.html">Change language information (internationalisation)</a></li>
  270. <li><a href="../basic_init/themes.html">ThemeRoller themes (Smoothness)</a></li>
  271. </ul>
  272. <h2>Advanced initialisation</h2>
  273. <ul>
  274. <li><a href="../advanced_init/events_pre_init.html">Events (pre initialisation)</a></li>
  275. <li><a href="../advanced_init/events_post_init.html">Events (post initialisation)</a></li>
  276. <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
  277. <li><a href="../advanced_init/html_sort.html">Sorting without HTML tags</a></li>
  278. <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table controls (sDom)</a></li>
  279. <li><a href="../advanced_init/length_menu.html">Defining length menu options</a></li>
  280. <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar (element) around table</a></li>
  281. <li><a href="../advanced_init/highlight.html">Row highlighting with CSS</a></li>
  282. <li><a href="../advanced_init/complex_header.html">Column grouping through col/row spans</a></li>
  283. <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
  284. <li><a href="../advanced_init/row_callback.html">Row callback</a></li>
  285. <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
  286. <li><a href="../advanced_init/language_file.html">Change language information from a file (internationalisation)</a></li>
  287. </ul>
  288. <h2>Data sources</h2>
  289. <ul>
  290. <li><a href="../data_sources/dom.html">DOM</a></li>
  291. <li><a href="../data_sources/js_array.html">Javascript array</a></li>
  292. <li><a href="../data_sources/ajax.html">Ajax source</a></li>
  293. <li><a href="../data_sources/server_side.html">Server side processing</a></li>
  294. </ul>
  295. <h2>Server-side processing</h2>
  296. <ul>
  297. <li><a href="../server_side/server_side.html">Obtain server-side data</a></li>
  298. <li><a href="../server_side/custom_vars.html">Add extra HTTP variables</a></li>
  299. <li><a href="../server_side/post.html">Use HTTP POST</a></li>
  300. <li><a href="../server_side/column_ordering.html">Custom column ordering (in callback data)</a></li>
  301. <li><a href="../server_side/pipeline.html">Pipelining data (reduce Ajax calls for paging)</a></li>
  302. <li><a href="../server_side/row_details.html">Show and hide details about a particular record</a></li>
  303. <li><a href="../server_side/select_rows.html">User selectable rows (multiple rows)</a></li>
  304. </ul>
  305. <h2>API</h2>
  306. <ul>
  307. <li><a href="../api/add_row.html">Dynamically add a new row</a></li>
  308. <li><a href="../api/multi_filter.html">Individual column filtering (using "input" elements)</a></li>
  309. <li><a href="../api/multi_filter_select.html">Individual column filtering (using "select" elements)</a></li>
  310. <li><a href="../api/highlight.html">Highlight rows and columns</a></li>
  311. <li><a href="../api/row_details.html">Show and hide details about a particular record</a></li>
  312. <li><a href="../api/select_row.html">User selectable rows (multiple rows)</a></li>
  313. <li><a href="../api/select_single_row.html">User selectable rows (single row) and delete rows</a></li>
  314. <li><a href="../api/editable.html">Editable rows (with jEditable)</a></li>
  315. <li><a href="../api/form.html">Submit form with elements in table</a></li>
  316. <li><a href="../api/counter_column.html">Index column (static number column)</a></li>
  317. <li><a href="../api/show_hide.html">Show and hide columns dynamically</a></li>
  318. <li><a href="../api/api_in_init.html">API function use in initialisation object (callback)</a></li>
  319. <li><a href="../api/tabs_and_scrolling.html">DataTables scrolling and tabs</a></li>
  320. <li><a href="../api/regex.html">Regular expression filtering</a></li>
  321. </ul>
  322. <h2>Plug-ins</h2>
  323. <ul>
  324. <li><a href="../plug-ins/plugin_api.html">Add custom API functions</a></li>
  325. <li><a href="../plug-ins/sorting_plugin.html">Sorting and type detection</a></li>
  326. <li><a href="../plug-ins/paging_plugin.html">Custom pagination controls</a></li>
  327. <li><a href="../plug-ins/range_filtering.html">Range filtering / custom filtering</a></li>
  328. <li><a href="../plug-ins/dom_sort.html">Live DOM sorting</a></li>
  329. <li><a href="../plug-ins/html_sort.html">Automatic HTML type detection</a></li>
  330. </ul>
  331. <p>Please refer to the <a href="http://www.datatables.net/"><i>DataTables</i> documentation</a> for full information about its API properties and methods.</p>
  332. <div id="footer" style="text-align:center;">
  333. <span style="font-size:10px;">DataTables &copy; Allan Jardine 2008-2010</span>
  334. </div>
  335. </div>
  336. </body>
  337. </html>