PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/public/assets/global/plugins/datatables/examples/server_side/select_rows.html

https://gitlab.com/ealexis.t/trends
HTML | 344 lines | 303 code | 41 blank | 0 comment | 0 complexity | f160db0a2a1b9d7ad9773ec0640be77e MD5 | raw file
  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>DataTables example - Row selection</title>
  8. <link rel="stylesheet" type="text/css" href="../../media/css/jquery.dataTables.css">
  9. <link rel="stylesheet" type="text/css" href="../resources/syntax/shCore.css">
  10. <link rel="stylesheet" type="text/css" href="../resources/demo.css">
  11. <style type="text/css" class="init">
  12. </style>
  13. <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
  14. <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
  15. <script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js"></script>
  16. <script type="text/javascript" language="javascript" src="../resources/demo.js"></script>
  17. <script type="text/javascript" language="javascript" class="init">
  18. $(document).ready(function() {
  19. var selected = [];
  20. $("#example").dataTable({
  21. "processing": true,
  22. "serverSide": true,
  23. "ajax": "scripts/ids-arrays.php",
  24. "rowCallback": function( row, data, displayIndex ) {
  25. if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
  26. $(row).addClass('selected');
  27. }
  28. }
  29. });
  30. $('#example tbody').on('click', 'tr', function () {
  31. var id = this.id;
  32. var index = $.inArray(id, selected);
  33. if ( index === -1 ) {
  34. selected.push( id );
  35. } else {
  36. selected.splice( index, 1 );
  37. }
  38. $(this).toggleClass('selected');
  39. } );
  40. } );
  41. </script>
  42. </head>
  43. <body class="dt-example">
  44. <div class="container">
  45. <section>
  46. <h1>DataTables example <span>Row selection</span></h1>
  47. <div class="info">
  48. <p>When you want to have user selectable rows in DataTables, it is relatively trivial when using DOM
  49. based data - but when using server-side processing, DataTables doesn't retain DOM row elements over
  50. pages / filtering etc. As such, you will need to keep a track of which rows a user as selected and mark
  51. them as selected on each draw.</p>
  52. <p>This is shown in this demo, which uses a unique ID assigned to the TR element (this is done
  53. automatically through the use of the <code>DT_RowId</code> special property returned as part of the
  54. object given by the server for each row) to track which rows are selected and reselect them is
  55. appropriate on a draw.</p>
  56. </div>
  57. <table id="example" class="display" cellspacing="0" width="100%">
  58. <thead>
  59. <tr>
  60. <th>Name</th>
  61. <th>Position</th>
  62. <th>Office</th>
  63. <th>Extn.</th>
  64. <th>Start date</th>
  65. <th>Salary</th>
  66. </tr>
  67. </thead>
  68. <tfoot>
  69. <tr>
  70. <th>Name</th>
  71. <th>Position</th>
  72. <th>Office</th>
  73. <th>Extn.</th>
  74. <th>Start date</th>
  75. <th>Salary</th>
  76. </tr>
  77. </tfoot>
  78. </table>
  79. <ul class="tabs">
  80. <li class="active">Javascript</li>
  81. <li>HTML</li>
  82. <li>CSS</li>
  83. <li>Ajax</li>
  84. <li>Server-side script</li>
  85. </ul>
  86. <div class="tabs">
  87. <div class="js">
  88. <p>The Javascript shown below is used to initialise the table shown in this
  89. example:</p><code class="multiline brush: js;">$(document).ready(function() {
  90. var selected = [];
  91. $(&quot;#example&quot;).dataTable({
  92. &quot;processing&quot;: true,
  93. &quot;serverSide&quot;: true,
  94. &quot;ajax&quot;: &quot;scripts/ids-arrays.php&quot;,
  95. &quot;rowCallback&quot;: function( row, data, displayIndex ) {
  96. if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
  97. $(row).addClass('selected');
  98. }
  99. }
  100. });
  101. $('#example tbody').on('click', 'tr', function () {
  102. var id = this.id;
  103. var index = $.inArray(id, selected);
  104. if ( index === -1 ) {
  105. selected.push( id );
  106. } else {
  107. selected.splice( index, 1 );
  108. }
  109. $(this).toggleClass('selected');
  110. } );
  111. } );</code>
  112. <p>In addition to the above code, the following Javascript library files are loaded for use in this
  113. example:</p>
  114. <ul>
  115. <li><a href="../../media/js/jquery.js">../../media/js/jquery.js</a></li>
  116. <li><a href="../../media/js/jquery.dataTables.js">../../media/js/jquery.dataTables.js</a></li>
  117. </ul>
  118. </div>
  119. <div class="table">
  120. <p>The HTML shown below is the raw HTML table element, before it has been enhanced by
  121. DataTables:</p>
  122. </div>
  123. <div class="css">
  124. <div>
  125. <p>This example uses a little bit of additional CSS beyond what is loaded from the library
  126. files (below), in order to correctly display the table. The additional CSS used is shown
  127. below:</p><code class="multiline brush: js;"></code>
  128. </div>
  129. <p>The following CSS library files are loaded for use in this example to provide the styling of the
  130. table:</p>
  131. <ul>
  132. <li><a href=
  133. "../../media/css/jquery.dataTables.css">../../media/css/jquery.dataTables.css</a></li>
  134. </ul>
  135. </div>
  136. <div class="ajax">
  137. <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
  138. will update automatically as any additional data is loaded.</p>
  139. </div>
  140. <div class="php">
  141. <p>The script used to perform the server-side processing for this table is shown below. Please note
  142. that this is just an example script using PHP. Server-side processing scripts can be written in any
  143. language, using <a href="//datatables.net/manual/server-side">the protocol described in the
  144. DataTables documentation</a>.</p>
  145. </div>
  146. </div>
  147. </section>
  148. </div>
  149. <section>
  150. <div class="footer">
  151. <div class="gradient"></div>
  152. <div class="liner">
  153. <h2>Other examples</h2>
  154. <div class="toc">
  155. <div class="toc-group">
  156. <h3><a href="../basic_init/index.html">Basic initialisation</a></h3>
  157. <ul class="toc">
  158. <li><a href="../basic_init/zero_configuration.html">Zero configuration</a></li>
  159. <li><a href="../basic_init/filter_only.html">Feature enable / disable</a></li>
  160. <li><a href="../basic_init/table_sorting.html">Default ordering (sorting)</a></li>
  161. <li><a href="../basic_init/multi_col_sort.html">Multi-column ordering</a></li>
  162. <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
  163. <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
  164. <li><a href="../basic_init/complex_header.html">Complex headers (rowspan and
  165. colspan)</a></li>
  166. <li><a href="../basic_init/dom.html">DOM positioning</a></li>
  167. <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li>
  168. <li><a href="../basic_init/state_save.html">State saving</a></li>
  169. <li><a href="../basic_init/alt_pagination.html">Alternative pagination</a></li>
  170. <li><a href="../basic_init/scroll_y.html">Scroll - vertical</a></li>
  171. <li><a href="../basic_init/scroll_x.html">Scroll - horizontal</a></li>
  172. <li><a href="../basic_init/scroll_xy.html">Scroll - horizontal and vertical</a></li>
  173. <li><a href="../basic_init/scroll_y_theme.html">Scroll - vertical with jQuery UI
  174. ThemeRoller</a></li>
  175. <li><a href="../basic_init/comma-decimal.html">Language - Comma decimal place</a></li>
  176. <li><a href="../basic_init/language.html">Language options</a></li>
  177. </ul>
  178. </div>
  179. <div class="toc-group">
  180. <h3><a href="../advanced_init/index.html">Advanced initialisation</a></h3>
  181. <ul class="toc">
  182. <li><a href="../advanced_init/events_live.html">DOM / jQuery events</a></li>
  183. <li><a href="../advanced_init/dt_events.html">DataTables events</a></li>
  184. <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
  185. <li><a href="../advanced_init/length_menu.html">Page length options</a></li>
  186. <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table control
  187. elements</a></li>
  188. <li><a href="../advanced_init/complex_header.html">Complex headers (rowspan /
  189. colspan)</a></li>
  190. <li><a href="../advanced_init/html5-data-attributes.html">HTML5 data-* attributes</a></li>
  191. <li><a href="../advanced_init/language_file.html">Language file</a></li>
  192. <li><a href="../advanced_init/defaults.html">Setting defaults</a></li>
  193. <li><a href="../advanced_init/row_callback.html">Row created callback</a></li>
  194. <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
  195. <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
  196. <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar elements</a></li>
  197. <li><a href="../advanced_init/sort_direction_control.html">Order direction sequence
  198. control</a></li>
  199. </ul>
  200. </div>
  201. <div class="toc-group">
  202. <h3><a href="../styling/index.html">Styling</a></h3>
  203. <ul class="toc">
  204. <li><a href="../styling/display.html">Base style</a></li>
  205. <li><a href="../styling/no-classes.html">Base style - no styling classes</a></li>
  206. <li><a href="../styling/cell-border.html">Base style - cell borders</a></li>
  207. <li><a href="../styling/compact.html">Base style - compact</a></li>
  208. <li><a href="../styling/hover.html">Base style - hover</a></li>
  209. <li><a href="../styling/order-column.html">Base style - order-column</a></li>
  210. <li><a href="../styling/row-border.html">Base style - row borders</a></li>
  211. <li><a href="../styling/stripe.html">Base style - stripe</a></li>
  212. <li><a href="../styling/bootstrap.html">Bootstrap</a></li>
  213. <li><a href="../styling/foundation.html">Foundation</a></li>
  214. <li><a href="../styling/jqueryUI.html">jQuery UI ThemeRoller</a></li>
  215. </ul>
  216. </div>
  217. <div class="toc-group">
  218. <h3><a href="../data_sources/index.html">Data sources</a></h3>
  219. <ul class="toc">
  220. <li><a href="../data_sources/dom.html">HTML (DOM) sourced data</a></li>
  221. <li><a href="../data_sources/ajax.html">Ajax sourced data</a></li>
  222. <li><a href="../data_sources/js_array.html">Javascript sourced data</a></li>
  223. <li><a href="../data_sources/server_side.html">Server-side processing</a></li>
  224. </ul>
  225. </div>
  226. <div class="toc-group">
  227. <h3><a href="../api/index.html">API</a></h3>
  228. <ul class="toc">
  229. <li><a href="../api/add_row.html">Add rows</a></li>
  230. <li><a href="../api/multi_filter.html">Individual column searching (text inputs)</a></li>
  231. <li><a href="../api/multi_filter_select.html">Individual column searching (select
  232. inputs)</a></li>
  233. <li><a href="../api/highlight.html">Highlighting rows and columns</a></li>
  234. <li><a href="../api/row_details.html">Child rows (show extra / detailed
  235. information)</a></li>
  236. <li><a href="../api/select_row.html">Row selection (multiple rows)</a></li>
  237. <li><a href="../api/select_single_row.html">Row selection and deletion (single
  238. row)</a></li>
  239. <li><a href="../api/form.html">Form inputs</a></li>
  240. <li><a href="../api/counter_columns.html">Index column</a></li>
  241. <li><a href="../api/show_hide.html">Show / hide columns dynamically</a></li>
  242. <li><a href="../api/api_in_init.html">Using API in callbacks</a></li>
  243. <li><a href="../api/tabs_and_scrolling.html">Scrolling and jQuery UI tabs</a></li>
  244. <li><a href="../api/regex.html">Search API (regular expressions)</a></li>
  245. </ul>
  246. </div>
  247. <div class="toc-group">
  248. <h3><a href="../ajax/index.html">Ajax</a></h3>
  249. <ul class="toc">
  250. <li><a href="../ajax/simple.html">Ajax data source (arrays)</a></li>
  251. <li><a href="../ajax/objects.html">Ajax data source (objects)</a></li>
  252. <li><a href="../ajax/deep.html">Nested object data (objects)</a></li>
  253. <li><a href="../ajax/objects_subarrays.html">Nested object data (arrays)</a></li>
  254. <li><a href="../ajax/orthogonal-data.html">Orthogonal data</a></li>
  255. <li><a href="../ajax/null_data_source.html">Generated content for a column</a></li>
  256. <li><a href="../ajax/custom_data_property.html">Custom data source property</a></li>
  257. <li><a href="../ajax/custom_data_flat.html">Flat array data source</a></li>
  258. <li><a href="../ajax/defer_render.html">Deferred rendering for speed</a></li>
  259. </ul>
  260. </div>
  261. <div class="toc-group">
  262. <h3><a href="./index.html">Server-side</a></h3>
  263. <ul class="toc active">
  264. <li><a href="./simple.html">Server-side processing</a></li>
  265. <li><a href="./custom_vars.html">Custom HTTP variables</a></li>
  266. <li><a href="./post.html">POST data</a></li>
  267. <li><a href="./ids.html">Automatic addition of row ID attributes</a></li>
  268. <li><a href="./object_data.html">Object data source</a></li>
  269. <li><a href="./row_details.html">Row details</a></li>
  270. <li class="active"><a href="./select_rows.html">Row selection</a></li>
  271. <li><a href="./jsonp.html">JSONP data source for remote domains</a></li>
  272. <li><a href="./defer_loading.html">Deferred loading of data</a></li>
  273. <li><a href="./pipeline.html">Pipelining data to reduce Ajax calls for paging</a></li>
  274. </ul>
  275. </div>
  276. <div class="toc-group">
  277. <h3><a href="../plug-ins/index.html">Plug-ins</a></h3>
  278. <ul class="toc">
  279. <li><a href="../plug-ins/api.html">API plug-in methods</a></li>
  280. <li><a href="../plug-ins/sorting_auto.html">Ordering plug-ins (with type
  281. detection)</a></li>
  282. <li><a href="../plug-ins/sorting_manual.html">Ordering plug-ins (no type
  283. detection)</a></li>
  284. <li><a href="../plug-ins/range_filtering.html">Custom filtering - range search</a></li>
  285. <li><a href="../plug-ins/dom_sort.html">Live DOM ordering</a></li>
  286. </ul>
  287. </div>
  288. </div>
  289. <div class="epilogue">
  290. <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
  291. information about its API properties and methods.<br>
  292. Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
  293. <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
  294. DataTables.</p>
  295. <p class="copyright">DataTables designed and created by <a href=
  296. "http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2014<br>
  297. DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
  298. </div>
  299. </div>
  300. </div>
  301. </section>
  302. </body>
  303. </html>