tabs_and_scrolling.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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/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_jui.css";
  10. @import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
  11. .ui-tabs .ui-tabs-panel { padding: 10px }
  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="../examples_support/jquery-ui-tabs.js"></script>
  16. <script type="text/javascript" charset="utf-8">
  17. $(document).ready(function() {
  18. $("#tabs").tabs( {
  19. "show": function(event, ui) {
  20. var table = $.fn.dataTable.fnTables(true);
  21. if ( table.length > 0 ) {
  22. $(table).dataTable().fnAdjustColumnSizing();
  23. }
  24. }
  25. } );
  26. $('table.display').dataTable( {
  27. "sScrollY": "200px",
  28. "bScrollCollapse": true,
  29. "bPaginate": false,
  30. "bJQueryUI": true,
  31. "aoColumnDefs": [
  32. { "sWidth": "10%", "aTargets": [ -1 ] }
  33. ]
  34. } );
  35. } );
  36. </script>
  37. </head>
  38. <body id="dt_example">
  39. <div id="container">
  40. <div class="full_width big">
  41. DataTables scrolling and jQuery UI tabs
  42. </div>
  43. <h1>Preamble</h1>
  44. <p>This example shows how DataTables with scrolling can be used together with jQuery UI tabs (or indeed any other method whereby the table is in a hidden (display:none) element when it is initialised). The reason this requires special consideration, is that when DataTables is initialised and it is in a hidden element, the browser doesn't have any measurements with which to give DataTables, and this will require in the misalignment of columns when scrolling is enabled.</p>
  45. <p>The method to get around this is to call the fnAdjustColumnSizing API function. This function will calculate the column widths that are needed based on the current data and then redraw the table - which is exactly what is needed when the table becomes visible for the first time. For this we use the 'show' method provided by jQuery UI tables. We check to see if the DataTable has been created or not (note the extra selector for 'div.dataTables_scrollBody', this is added when the DataTable is initialised). If the table has been initialised, we re-size it. An optimisation could be added to re-size only of the first showing of the table.</p>
  46. <h1>Live example</h1>
  47. <div id="demo">
  48. <div id="tabs">
  49. <ul>
  50. <li><a href="#tabs-1">Trident browsers</a></li>
  51. <li><a href="#tabs-2">Gecko browsers</a></li>
  52. </ul>
  53. <div id="tabs-1">
  54. <table cellpadding="0" cellspacing="0" border="0" class="display" id="example1">
  55. <thead>
  56. <tr>
  57. <th>Rendering engine</th>
  58. <th>Browser</th>
  59. <th>Platform(s)</th>
  60. <th>Engine version</th>
  61. <th>Grade</th>
  62. </tr>
  63. </thead>
  64. <tfoot>
  65. <tr>
  66. <th>Rendering engine</th>
  67. <th>Browser</th>
  68. <th>Platform(s)</th>
  69. <th>Engine version</th>
  70. <th>Grade</th>
  71. </tr>
  72. </tfoot>
  73. <tbody>
  74. <tr class="odd gradeX">
  75. <td>Trident</td>
  76. <td>Internet
  77. Explorer 4.0</td>
  78. <td>Win 95+</td>
  79. <td class="center">4</td>
  80. <td class="center">X</td>
  81. </tr>
  82. <tr class="odd gradeC">
  83. <td>Trident</td>
  84. <td>Internet
  85. Explorer 5.0</td>
  86. <td>Win 95+</td>
  87. <td class="center">5</td>
  88. <td class="center">C</td>
  89. </tr>
  90. <tr class="odd gradeA">
  91. <td>Trident</td>
  92. <td>Internet
  93. Explorer 5.5</td>
  94. <td>Win 95+</td>
  95. <td class="center">5.5</td>
  96. <td class="center">A</td>
  97. </tr>
  98. <tr class="odd gradeA">
  99. <td>Trident</td>
  100. <td>Internet
  101. Explorer 6</td>
  102. <td>Win 98+</td>
  103. <td class="center">6</td>
  104. <td class="center">A</td>
  105. </tr>
  106. <tr class="odd gradeA">
  107. <td>Trident</td>
  108. <td>Internet Explorer 7</td>
  109. <td>Win XP SP2+</td>
  110. <td class="center">7</td>
  111. <td class="center">A</td>
  112. </tr>
  113. <tr class="odd gradeA">
  114. <td>Trident</td>
  115. <td>AOL browser (AOL desktop)</td>
  116. <td>Win XP</td>
  117. <td class="center">6</td>
  118. <td class="center">A</td>
  119. </tr>
  120. <tbody>
  121. </table>
  122. </div>
  123. <div id="tabs-2">
  124. <table cellpadding="0" cellspacing="0" border="0" class="display" id="example2">
  125. <thead>
  126. <tr>
  127. <th>Rendering engine</th>
  128. <th>Browser</th>
  129. <th>Platform(s)</th>
  130. <th>Engine version</th>
  131. <th>Grade</th>
  132. </tr>
  133. </thead>
  134. <tfoot>
  135. <tr>
  136. <th>Rendering engine</th>
  137. <th>Browser</th>
  138. <th>Platform(s)</th>
  139. <th>Engine version</th>
  140. <th>Grade</th>
  141. </tr>
  142. </tfoot>
  143. <tbody>
  144. <tr class="gradeA">
  145. <td>Gecko</td>
  146. <td>Firefox 1.0</td>
  147. <td>Win 98+ / OSX.2+</td>
  148. <td class="center">1.7</td>
  149. <td class="center">A</td>
  150. </tr>
  151. <tr class="gradeA">
  152. <td>Gecko</td>
  153. <td>Firefox 1.5</td>
  154. <td>Win 98+ / OSX.2+</td>
  155. <td class="center">1.8</td>
  156. <td class="center">A</td>
  157. </tr>
  158. <tr class="gradeA">
  159. <td>Gecko</td>
  160. <td>Firefox 2.0</td>
  161. <td>Win 98+ / OSX.2+</td>
  162. <td class="center">1.8</td>
  163. <td class="center">A</td>
  164. </tr>
  165. <tr class="gradeA">
  166. <td>Gecko</td>
  167. <td>Firefox 3.0</td>
  168. <td>Win 2k+ / OSX.3+</td>
  169. <td class="center">1.9</td>
  170. <td class="center">A</td>
  171. </tr>
  172. <tr class="gradeA">
  173. <td>Gecko</td>
  174. <td>Camino 1.0</td>
  175. <td>OSX.2+</td>
  176. <td class="center">1.8</td>
  177. <td class="center">A</td>
  178. </tr>
  179. <tr class="gradeA">
  180. <td>Gecko</td>
  181. <td>Camino 1.5</td>
  182. <td>OSX.3+</td>
  183. <td class="center">1.8</td>
  184. <td class="center">A</td>
  185. </tr>
  186. <tr class="gradeA">
  187. <td>Gecko</td>
  188. <td>Netscape 7.2</td>
  189. <td>Win 95+ / Mac OS 8.6-9.2</td>
  190. <td class="center">1.7</td>
  191. <td class="center">A</td>
  192. </tr>
  193. <tr class="gradeA">
  194. <td>Gecko</td>
  195. <td>Netscape Browser 8</td>
  196. <td>Win 98SE+</td>
  197. <td class="center">1.7</td>
  198. <td class="center">A</td>
  199. </tr>
  200. <tr class="gradeA">
  201. <td>Gecko</td>
  202. <td>Netscape Navigator 9</td>
  203. <td>Win 98+ / OSX.2+</td>
  204. <td class="center">1.8</td>
  205. <td class="center">A</td>
  206. </tr>
  207. <tr class="gradeA">
  208. <td>Gecko</td>
  209. <td>Mozilla 1.0</td>
  210. <td>Win 95+ / OSX.1+</td>
  211. <td class="center">1</td>
  212. <td class="center">A</td>
  213. </tr>
  214. <tr class="gradeA">
  215. <td>Gecko</td>
  216. <td>Mozilla 1.1</td>
  217. <td>Win 95+ / OSX.1+</td>
  218. <td class="center">1.1</td>
  219. <td class="center">A</td>
  220. </tr>
  221. <tr class="gradeA">
  222. <td>Gecko</td>
  223. <td>Mozilla 1.2</td>
  224. <td>Win 95+ / OSX.1+</td>
  225. <td class="center">1.2</td>
  226. <td class="center">A</td>
  227. </tr>
  228. <tr class="gradeA">
  229. <td>Gecko</td>
  230. <td>Mozilla 1.3</td>
  231. <td>Win 95+ / OSX.1+</td>
  232. <td class="center">1.3</td>
  233. <td class="center">A</td>
  234. </tr>
  235. <tr class="gradeA">
  236. <td>Gecko</td>
  237. <td>Mozilla 1.4</td>
  238. <td>Win 95+ / OSX.1+</td>
  239. <td class="center">1.4</td>
  240. <td class="center">A</td>
  241. </tr>
  242. <tr class="gradeA">
  243. <td>Gecko</td>
  244. <td>Mozilla 1.5</td>
  245. <td>Win 95+ / OSX.1+</td>
  246. <td class="center">1.5</td>
  247. <td class="center">A</td>
  248. </tr>
  249. <tr class="gradeA">
  250. <td>Gecko</td>
  251. <td>Mozilla 1.6</td>
  252. <td>Win 95+ / OSX.1+</td>
  253. <td class="center">1.6</td>
  254. <td class="center">A</td>
  255. </tr>
  256. <tr class="gradeA">
  257. <td>Gecko</td>
  258. <td>Mozilla 1.7</td>
  259. <td>Win 98+ / OSX.1+</td>
  260. <td class="center">1.7</td>
  261. <td class="center">A</td>
  262. </tr>
  263. <tr class="gradeA">
  264. <td>Gecko</td>
  265. <td>Mozilla 1.8</td>
  266. <td>Win 98+ / OSX.1+</td>
  267. <td class="center">1.8</td>
  268. <td class="center">A</td>
  269. </tr>
  270. <tr class="gradeA">
  271. <td>Gecko</td>
  272. <td>Seamonkey 1.1</td>
  273. <td>Win 98+ / OSX.2+</td>
  274. <td class="center">1.8</td>
  275. <td class="center">A</td>
  276. </tr>
  277. <tr class="gradeA">
  278. <td>Gecko</td>
  279. <td>Epiphany 2.20</td>
  280. <td>Gnome</td>
  281. <td class="center">1.8</td>
  282. <td class="center">A</td>
  283. </tr>
  284. </tbody>
  285. </table>
  286. </div>
  287. </div>
  288. </div>
  289. <div class="spacer"></div>
  290. <h1>Initialisation code</h1>
  291. <pre class="brush: js;">$(document).ready(function() {
  292. $("#tabs").tabs( {
  293. "show": function(event, ui) {
  294. var table = $.fn.dataTable.fnTables(true);
  295. if ( table.length &gt; 0 ) {
  296. $(table).dataTable().fnAdjustColumnSizing();
  297. }
  298. }
  299. } );
  300. $('table.display').dataTable( {
  301. "sScrollY": "200px",
  302. "bScrollCollapse": true,
  303. "bPaginate": false,
  304. "bJQueryUI": true,
  305. "aoColumnDefs": [
  306. { "sWidth": "10%", "aTargets": [ -1 ] }
  307. ]
  308. } );
  309. } );</pre>
  310. <style type="text/css">
  311. @import "../examples_support/syntax/css/shCore.css";
  312. </style>
  313. <script type="text/javascript" language="javascript" src="../examples_support/syntax/js/shCore.js"></script>
  314. <h1>Other examples</h1>
  315. <div class="demo_links">
  316. <h2>Basic initialisation</h2>
  317. <ul>
  318. <li><a href="../basic_init/zero_config.html">Zero configuration</a></li>
  319. <li><a href="../basic_init/filter_only.html">Feature enablement</a></li>
  320. <li><a href="../basic_init/table_sorting.html">Sorting data</a></li>
  321. <li><a href="../basic_init/multi_col_sort.html">Multi-column sorting</a></li>
  322. <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
  323. <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
  324. <li><a href="../basic_init/complex_header.html">Complex headers - grouping with colspan</a></li>
  325. <li><a href="../basic_init/dom.html">DOM positioning</a></li>
  326. <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li>
  327. <li><a href="../basic_init/state_save.html">State saving</a></li>
  328. <li><a href="../basic_init/alt_pagination.html">Alternative pagination styles</a></li>
  329. <li>Scrolling: <br>
  330. <a href="../basic_init/scroll_x.html">Horizontal</a> /
  331. <a href="../basic_init/scroll_y.html">Vertical</a> /
  332. <a href="../basic_init/scroll_xy.html">Both</a> /
  333. <a href="../basic_init/scroll_y_theme.html">Themed</a> /
  334. <a href="../basic_init/scroll_y_infinite.html">Infinite</a>
  335. </li>
  336. <li><a href="../basic_init/language.html">Change language information (internationalisation)</a></li>
  337. <li><a href="../basic_init/themes.html">ThemeRoller themes (Smoothness)</a></li>
  338. </ul>
  339. <h2>Advanced initialisation</h2>
  340. <ul>
  341. <li>Events: <br>
  342. <a href="../advanced_init/events_live.html">Live events</a> /
  343. <a href="../advanced_init/events_pre_init.html">Pre-init</a> /
  344. <a href="../advanced_init/events_post_init.html">Post-init</a>
  345. </li>
  346. <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
  347. <li><a href="../advanced_init/html_sort.html">Sorting without HTML tags</a></li>
  348. <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table controls (sDom)</a></li>
  349. <li><a href="../advanced_init/length_menu.html">Defining length menu options</a></li>
  350. <li><a href="../advanced_init/complex_header.html">Complex headers and hidden columns</a></li>
  351. <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar (element) around table</a></li>
  352. <li><a href="../advanced_init/highlight.html">Row highlighting with CSS</a></li>
  353. <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
  354. <li><a href="../advanced_init/row_callback.html">Row callback</a></li>
  355. <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
  356. <li><a href="../advanced_init/sorting_control.html">Control sorting direction of columns</a></li>
  357. <li><a href="../advanced_init/language_file.html">Change language information from a file (internationalisation)</a></li>
  358. <li><a href="../advanced_init/defaults.html">Setting defaults</a></li>
  359. <li><a href="../advanced_init/localstorage.html">State saving with localStorage</a></li>
  360. <li><a href="../advanced_init/dt_events.html">Custom events</a></li>
  361. </ul>
  362. <h2>API</h2>
  363. <ul>
  364. <li><a href="../api/add_row.html">Dynamically add a new row</a></li>
  365. <li><a href="../api/multi_filter.html">Individual column filtering (using "input" elements)</a></li>
  366. <li><a href="../api/multi_filter_select.html">Individual column filtering (using "select" elements)</a></li>
  367. <li><a href="../api/highlight.html">Highlight rows and columns</a></li>
  368. <li><a href="../api/row_details.html">Show and hide details about a particular record</a></li>
  369. <li><a href="../api/select_row.html">User selectable rows (multiple rows)</a></li>
  370. <li><a href="../api/select_single_row.html">User selectable rows (single row) and delete rows</a></li>
  371. <li><a href="../api/editable.html">Editable rows (with jEditable)</a></li>
  372. <li><a href="../api/form.html">Submit form with elements in table</a></li>
  373. <li><a href="../api/counter_column.html">Index column (static number column)</a></li>
  374. <li><a href="../api/show_hide.html">Show and hide columns dynamically</a></li>
  375. <li><a href="../api/api_in_init.html">API function use in initialisation object (callback)</a></li>
  376. <li><a href="../api/tabs_and_scrolling.html">DataTables scrolling and tabs</a></li>
  377. <li><a href="../api/regex.html">Regular expression filtering</a></li>
  378. </ul>
  379. </div>
  380. <div class="demo_links">
  381. <h2>Data sources</h2>
  382. <ul>
  383. <li><a href="../data_sources/dom.html">DOM</a></li>
  384. <li><a href="../data_sources/js_array.html">Javascript array</a></li>
  385. <li><a href="../data_sources/ajax.html">Ajax source</a></li>
  386. <li><a href="../data_sources/server_side.html">Server side processing</a></li>
  387. </ul>
  388. <h2>Server-side processing</h2>
  389. <ul>
  390. <li><a href="../server_side/server_side.html">Obtain server-side data</a></li>
  391. <li><a href="../server_side/custom_vars.html">Add extra HTTP variables</a></li>
  392. <li><a href="../server_side/post.html">Use HTTP POST</a></li>
  393. <li><a href="../server_side/ids.html">Automatic addition of IDs and classes to rows</a></li>
  394. <li><a href="../server_side/object_data.html">Reading table data from objects</a></li>
  395. <li><a href="../server_side/row_details.html">Show and hide details about a particular record</a></li>
  396. <li><a href="../server_side/select_rows.html">User selectable rows (multiple rows)</a></li>
  397. <li><a href="../server_side/jsonp.html">JSONP for a cross domain data source</a></li>
  398. <li><a href="../server_side/editable.html">jEditable integration with DataTables</a></li>
  399. <li><a href="../server_side/defer_loading.html">Deferred loading of Ajax data</a></li>
  400. <li><a href="../server_side/pipeline.html">Pipelining data (reduce Ajax calls for paging)</a></li>
  401. </ul>
  402. <h2>Ajax data source</h2>
  403. <ul>
  404. <li><a href="../ajax/ajax.html">Ajax sourced data (array of arrays)</a></li>
  405. <li><a href="../ajax/objects.html">Ajax sourced data (array of objects)</a></li>
  406. <li><a href="../ajax/defer_render.html">Deferred DOM creation for extra speed</a></li>
  407. <li><a href="../ajax/null_data_source.html">Empty data source columns</a></li>
  408. <li><a href="../ajax/custom_data_property.html">Use a data source other than aaData (the default)</a></li>
  409. <li><a href="../ajax/objects_subarrays.html">Read column data from sub-arrays</a></li>
  410. <li><a href="../ajax/deep.html">Read column data from deeply nested properties</a></li>
  411. </ul>
  412. <h2>Plug-ins</h2>
  413. <ul>
  414. <li><a href="../plug-ins/plugin_api.html">Add custom API functions</a></li>
  415. <li><a href="../plug-ins/sorting_plugin.html">Sorting and automatic type detection</a></li>
  416. <li><a href="../plug-ins/sorting_sType.html">Sorting without automatic type detection</a></li>
  417. <li><a href="../plug-ins/paging_plugin.html">Custom pagination controls</a></li>
  418. <li><a href="../plug-ins/range_filtering.html">Range filtering / custom filtering</a></li>
  419. <li><a href="../plug-ins/dom_sort.html">Live DOM sorting</a></li>
  420. <li><a href="../plug-ins/html_sort.html">Automatic HTML type detection</a></li>
  421. </ul>
  422. </div>
  423. <div id="footer" class="clear" style="text-align:center;">
  424. <p>
  425. Please refer to the <a href="http://www.datatables.net/usage">DataTables documentation</a> for full information about its API properties and methods.<br>
  426. 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.
  427. </p>
  428. <span style="font-size:10px;">
  429. DataTables designed and created by <a href="http://www.sprymedia.co.uk">Allan Jardine</a> &copy; 2007-2011<br>
  430. 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>.
  431. </span>
  432. </div>
  433. </div>
  434. </body>
  435. </html>