server-side_processing.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
  6. <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
  7. <title>Scroller example - Server-side processing (5,000,000 rows)</title>
  8. <link rel="stylesheet" type="text/css" href="../../../media/css/jquery.dataTables.css">
  9. <link rel="stylesheet" type="text/css" href="../css/dataTables.scroller.css">
  10. <link rel="stylesheet" type="text/css" href="../../../examples/resources/syntax/shCore.css">
  11. <link rel="stylesheet" type="text/css" href="../../../examples/resources/demo.css">
  12. <style type="text/css" class="init">
  13. </style>
  14. <script type="text/javascript" language="javascript" src="../../../media/js/jquery.js"></script>
  15. <script type="text/javascript" language="javascript" src="../../../media/js/jquery.dataTables.js"></script>
  16. <script type="text/javascript" language="javascript" src="../js/dataTables.scroller.js"></script>
  17. <script type="text/javascript" language="javascript" src="../../../examples/resources/syntax/shCore.js"></script>
  18. <script type="text/javascript" language="javascript" src="../../../examples/resources/demo.js"></script>
  19. <script type="text/javascript" language="javascript" class="init">
  20. $(document).ready(function() {
  21. $('#example').DataTable( {
  22. serverSide: true,
  23. ordering: false,
  24. searching: false,
  25. ajax: function ( data, callback, settings ) {
  26. var out = [];
  27. for ( var i=data.start, ien=data.start+data.length ; i<ien ; i++ ) {
  28. out.push( [ i+'-1', i+'-2', i+'-3', i+'-4', i+'-5' ] );
  29. }
  30. setTimeout( function () {
  31. callback( {
  32. draw: data.draw,
  33. data: out,
  34. recordsTotal: 5000000,
  35. recordsFiltered: 5000000
  36. } );
  37. }, 50 );
  38. },
  39. dom: "rtiS",
  40. scrollY: 200,
  41. scroller: {
  42. loadingIndicator: true
  43. }
  44. } );
  45. } );
  46. </script>
  47. </head>
  48. <body class="dt-example">
  49. <div class="container">
  50. <section>
  51. <h1>Scroller example <span>Server-side processing (5,000,000 rows)</span></h1>
  52. <div class="info">
  53. <p>DataTables' server-side processing mode is a feature that naturally fits in with Scroller perfectly.
  54. Server-side processing can be used to show large data sets, with the server being used to do the data
  55. processing, and Scroller optimising the display of the data in a scrolling viewport.</p>
  56. <p>When using server-side processing, Scroller will wait a small amount of time to allow the scrolling
  57. to finish before requesting more data from the server (200mS by default). This prevents you from DoSing
  58. your own server!</p>
  59. <p>This example shows Scroller using server-side processing mode and 5 million rows.
  60. <strong>Important</strong> This particular example uses <a href=
  61. "//datatables.net/reference/option/ajax"><code class="option" title=
  62. "DataTables initialisation option">ajax<span>DT</span></code></a> as a function to 'fake' the data to
  63. show Scroller's ability to show large data sets. It does not have a real database behind it! You would
  64. normally not use <a href="//datatables.net/reference/option/ajax"><code class="option" title=
  65. "DataTables initialisation option">ajax<span>DT</span></code></a> as a function to generate data, but
  66. rather as a url for where to fetch the real data!</p>
  67. <p>In this example we also enable the <code>loadingIndicator</code> option of Scroller to show the end
  68. user what is happening when they scroll passed the currently loaded data.</p>
  69. </div>
  70. <table id="example" class="display" cellspacing="0" width="100%">
  71. <thead>
  72. <tr>
  73. <th>ID</th>
  74. <th>First name</th>
  75. <th>Last name</th>
  76. <th>ZIP / Post code</th>
  77. <th>Country</th>
  78. </tr>
  79. </thead>
  80. </table>
  81. <ul class="tabs">
  82. <li class="active">Javascript</li>
  83. <li>HTML</li>
  84. <li>CSS</li>
  85. <li>Ajax</li>
  86. <li>Server-side script</li>
  87. </ul>
  88. <div class="tabs">
  89. <div class="js">
  90. <p>The Javascript shown below is used to initialise the table shown in this
  91. example:</p><code class="multiline brush: js;">$(document).ready(function() {
  92. $('#example').DataTable( {
  93. serverSide: true,
  94. ordering: false,
  95. searching: false,
  96. ajax: function ( data, callback, settings ) {
  97. var out = [];
  98. for ( var i=data.start, ien=data.start+data.length ; i&lt;ien ; i++ ) {
  99. out.push( [ i+'-1', i+'-2', i+'-3', i+'-4', i+'-5' ] );
  100. }
  101. setTimeout( function () {
  102. callback( {
  103. draw: data.draw,
  104. data: out,
  105. recordsTotal: 5000000,
  106. recordsFiltered: 5000000
  107. } );
  108. }, 50 );
  109. },
  110. dom: &quot;rtiS&quot;,
  111. scrollY: 200,
  112. scroller: {
  113. loadingIndicator: true
  114. }
  115. } );
  116. } );</code>
  117. <p>In addition to the above code, the following Javascript library files are loaded for use in this
  118. example:</p>
  119. <ul>
  120. <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
  121. <li><a href=
  122. "../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
  123. <li><a href="../js/dataTables.scroller.js">../js/dataTables.scroller.js</a></li>
  124. </ul>
  125. </div>
  126. <div class="table">
  127. <p>The HTML shown below is the raw HTML table element, before it has been enhanced by
  128. DataTables:</p>
  129. </div>
  130. <div class="css">
  131. <div>
  132. <p>This example uses a little bit of additional CSS beyond what is loaded from the library
  133. files (below), in order to correctly display the table. The additional CSS used is shown
  134. below:</p><code class="multiline brush: js;"></code>
  135. </div>
  136. <p>The following CSS library files are loaded for use in this example to provide the styling of the
  137. table:</p>
  138. <ul>
  139. <li><a href=
  140. "../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
  141. <li><a href="../css/dataTables.scroller.css">../css/dataTables.scroller.css</a></li>
  142. </ul>
  143. </div>
  144. <div class="ajax">
  145. <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
  146. will update automatically as any additional data is loaded.</p>
  147. </div>
  148. <div class="php">
  149. <p>The script used to perform the server-side processing for this table is shown below. Please note
  150. that this is just an example script using PHP. Server-side processing scripts can be written in any
  151. language, using <a href="//datatables.net/manual/server-side">the protocol described in the
  152. DataTables documentation</a>.</p>
  153. </div>
  154. </div>
  155. </section>
  156. </div>
  157. <section>
  158. <div class="footer">
  159. <div class="gradient"></div>
  160. <div class="liner">
  161. <h2>Other examples</h2>
  162. <div class="toc">
  163. <div class="toc-group">
  164. <h3><a href="./index.html">Examples</a></h3>
  165. <ul class="toc active">
  166. <li><a href="./simple.html">Basic initialisation</a></li>
  167. <li><a href="./state_saving.html">State saving</a></li>
  168. <li><a href="./large_js_source.html">Client-side data source (50,000 rows)</a></li>
  169. <li class="active"><a href="./server-side_processing.html">Server-side processing
  170. (5,000,000 rows)</a></li>
  171. <li><a href="./api_scrolling.html">API</a></li>
  172. </ul>
  173. </div>
  174. </div>
  175. <div class="epilogue">
  176. <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
  177. information about its API properties and methods.<br>
  178. Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
  179. <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
  180. DataTables.</p>
  181. <p class="copyright">DataTables designed and created by <a href=
  182. "http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2014<br>
  183. DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
  184. </div>
  185. </div>
  186. </div>
  187. </section>
  188. </body>
  189. </html>