js_array.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. /* Data set - can contain whatever information you want */
  15. var aDataSet = [
  16. ['Trident','Internet Explorer 4.0','Win 95+','4','X'],
  17. ['Trident','Internet Explorer 5.0','Win 95+','5','C'],
  18. ['Trident','Internet Explorer 5.5','Win 95+','5.5','A'],
  19. ['Trident','Internet Explorer 6','Win 98+','6','A'],
  20. ['Trident','Internet Explorer 7','Win XP SP2+','7','A'],
  21. ['Trident','AOL browser (AOL desktop)','Win XP','6','A'],
  22. ['Gecko','Firefox 1.0','Win 98+ / OSX.2+','1.7','A'],
  23. ['Gecko','Firefox 1.5','Win 98+ / OSX.2+','1.8','A'],
  24. ['Gecko','Firefox 2.0','Win 98+ / OSX.2+','1.8','A'],
  25. ['Gecko','Firefox 3.0','Win 2k+ / OSX.3+','1.9','A'],
  26. ['Gecko','Camino 1.0','OSX.2+','1.8','A'],
  27. ['Gecko','Camino 1.5','OSX.3+','1.8','A'],
  28. ['Gecko','Netscape 7.2','Win 95+ / Mac OS 8.6-9.2','1.7','A'],
  29. ['Gecko','Netscape Browser 8','Win 98SE+','1.7','A'],
  30. ['Gecko','Netscape Navigator 9','Win 98+ / OSX.2+','1.8','A'],
  31. ['Gecko','Mozilla 1.0','Win 95+ / OSX.1+',1,'A'],
  32. ['Gecko','Mozilla 1.1','Win 95+ / OSX.1+',1.1,'A'],
  33. ['Gecko','Mozilla 1.2','Win 95+ / OSX.1+',1.2,'A'],
  34. ['Gecko','Mozilla 1.3','Win 95+ / OSX.1+',1.3,'A'],
  35. ['Gecko','Mozilla 1.4','Win 95+ / OSX.1+',1.4,'A'],
  36. ['Gecko','Mozilla 1.5','Win 95+ / OSX.1+',1.5,'A'],
  37. ['Gecko','Mozilla 1.6','Win 95+ / OSX.1+',1.6,'A'],
  38. ['Gecko','Mozilla 1.7','Win 98+ / OSX.1+',1.7,'A'],
  39. ['Gecko','Mozilla 1.8','Win 98+ / OSX.1+',1.8,'A'],
  40. ['Gecko','Seamonkey 1.1','Win 98+ / OSX.2+','1.8','A'],
  41. ['Gecko','Epiphany 2.20','Gnome','1.8','A'],
  42. ['Webkit','Safari 1.2','OSX.3','125.5','A'],
  43. ['Webkit','Safari 1.3','OSX.3','312.8','A'],
  44. ['Webkit','Safari 2.0','OSX.4+','419.3','A'],
  45. ['Webkit','Safari 3.0','OSX.4+','522.1','A'],
  46. ['Webkit','OmniWeb 5.5','OSX.4+','420','A'],
  47. ['Webkit','iPod Touch / iPhone','iPod','420.1','A'],
  48. ['Webkit','S60','S60','413','A'],
  49. ['Presto','Opera 7.0','Win 95+ / OSX.1+','-','A'],
  50. ['Presto','Opera 7.5','Win 95+ / OSX.2+','-','A'],
  51. ['Presto','Opera 8.0','Win 95+ / OSX.2+','-','A'],
  52. ['Presto','Opera 8.5','Win 95+ / OSX.2+','-','A'],
  53. ['Presto','Opera 9.0','Win 95+ / OSX.3+','-','A'],
  54. ['Presto','Opera 9.2','Win 88+ / OSX.3+','-','A'],
  55. ['Presto','Opera 9.5','Win 88+ / OSX.3+','-','A'],
  56. ['Presto','Opera for Wii','Wii','-','A'],
  57. ['Presto','Nokia N800','N800','-','A'],
  58. ['Presto','Nintendo DS browser','Nintendo DS','8.5','C/A<sup>1</sup>'],
  59. ['KHTML','Konqureror 3.1','KDE 3.1','3.1','C'],
  60. ['KHTML','Konqureror 3.3','KDE 3.3','3.3','A'],
  61. ['KHTML','Konqureror 3.5','KDE 3.5','3.5','A'],
  62. ['Tasman','Internet Explorer 4.5','Mac OS 8-9','-','X'],
  63. ['Tasman','Internet Explorer 5.1','Mac OS 7.6-9','1','C'],
  64. ['Tasman','Internet Explorer 5.2','Mac OS 8-X','1','C'],
  65. ['Misc','NetFront 3.1','Embedded devices','-','C'],
  66. ['Misc','NetFront 3.4','Embedded devices','-','A'],
  67. ['Misc','Dillo 0.8','Embedded devices','-','X'],
  68. ['Misc','Links','Text only','-','X'],
  69. ['Misc','Lynx','Text only','-','X'],
  70. ['Misc','IE Mobile','Windows Mobile 6','-','C'],
  71. ['Misc','PSP browser','PSP','-','C'],
  72. ['Other browsers','All others','-','-','U']
  73. ];
  74. $(document).ready(function() {
  75. $('#dynamic').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
  76. $('#example').dataTable( {
  77. "aaData": aDataSet,
  78. "aoColumns": [
  79. { "sTitle": "Engine" },
  80. { "sTitle": "Browser" },
  81. { "sTitle": "Platform" },
  82. { "sTitle": "Version", "sClass": "center" },
  83. { "sTitle": "Grade", "sClass": "center" }
  84. ]
  85. } );
  86. } );
  87. </script>
  88. </head>
  89. <body id="dt_example">
  90. <div id="container">
  91. <div class="full_width big">
  92. DataTables dynamic creation example
  93. </div>
  94. <h1>Preamble</h1>
  95. <p>At times you will wish to be able to create a table from dynamic information passed directly to DataTables, rather than having it read from the document. This is achieved using the "aaData" array in the initialisation object. A table node must first be created before the initialiser is called (as shown in the code below). This is also useful for optimisation - if you are able to format the data as required, this method can save a lot of DOM parsing to create a table.</p>
  96. <h1>Live example</h1>
  97. <div id="dynamic"></div>
  98. <div class="spacer"></div>
  99. <h1>Initialisation code</h1>
  100. <pre class="brush: js;">$(document).ready(function() {
  101. $('#demo').html( '&lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt;&lt;/table&gt;' );
  102. $('#example').dataTable( {
  103. "aaData": [
  104. /* Reduced data set */
  105. [ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X" ],
  106. [ "Trident", "Internet Explorer 5.0", "Win 95+", 5, "C" ],
  107. [ "Trident", "Internet Explorer 5.5", "Win 95+", 5.5, "A" ],
  108. [ "Trident", "Internet Explorer 6.0", "Win 98+", 6, "A" ],
  109. [ "Trident", "Internet Explorer 7.0", "Win XP SP2+", 7, "A" ],
  110. [ "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", 1.8, "A" ],
  111. [ "Gecko", "Firefox 2", "Win 98+ / OSX.2+", 1.8, "A" ],
  112. [ "Gecko", "Firefox 3", "Win 2k+ / OSX.3+", 1.9, "A" ],
  113. [ "Webkit", "Safari 1.2", "OSX.3", 125.5, "A" ],
  114. [ "Webkit", "Safari 1.3", "OSX.3", 312.8, "A" ],
  115. [ "Webkit", "Safari 2.0", "OSX.4+", 419.3, "A" ],
  116. [ "Webkit", "Safari 3.0", "OSX.4+", 522.1, "A" ]
  117. ],
  118. "aoColumns": [
  119. { "sTitle": "Engine" },
  120. { "sTitle": "Browser" },
  121. { "sTitle": "Platform" },
  122. { "sTitle": "Version", "sClass": "center" },
  123. { "sTitle": "Grade", "sClass": "center" }
  124. ]
  125. } );
  126. } );</pre>
  127. <style type="text/css">
  128. @import "../examples_support/syntax/css/shCore.css";
  129. </style>
  130. <script type="text/javascript" language="javascript" src="../examples_support/syntax/js/shCore.js"></script>
  131. <h1>Other examples</h1>
  132. <div class="demo_links">
  133. <h2>Basic initialisation</h2>
  134. <ul>
  135. <li><a href="../basic_init/zero_config.html">Zero configuration</a></li>
  136. <li><a href="../basic_init/filter_only.html">Feature enablement</a></li>
  137. <li><a href="../basic_init/table_sorting.html">Sorting data</a></li>
  138. <li><a href="../basic_init/multi_col_sort.html">Multi-column sorting</a></li>
  139. <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
  140. <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
  141. <li><a href="../basic_init/complex_header.html">Complex headers - grouping with colspan</a></li>
  142. <li><a href="../basic_init/dom.html">DOM positioning</a></li>
  143. <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li>
  144. <li><a href="../basic_init/state_save.html">State saving</a></li>
  145. <li><a href="../basic_init/alt_pagination.html">Alternative pagination styles</a></li>
  146. <li>Scrolling: <br>
  147. <a href="../basic_init/scroll_x.html">Horizontal</a> /
  148. <a href="../basic_init/scroll_y.html">Vertical</a> /
  149. <a href="../basic_init/scroll_xy.html">Both</a> /
  150. <a href="../basic_init/scroll_y_theme.html">Themed</a> /
  151. <a href="../basic_init/scroll_y_infinite.html">Infinite</a>
  152. </li>
  153. <li><a href="../basic_init/language.html">Change language information (internationalisation)</a></li>
  154. <li><a href="../basic_init/themes.html">ThemeRoller themes (Smoothness)</a></li>
  155. </ul>
  156. <h2>Advanced initialisation</h2>
  157. <ul>
  158. <li>Events: <br>
  159. <a href="../advanced_init/events_live.html">Live events</a> /
  160. <a href="../advanced_init/events_pre_init.html">Pre-init</a> /
  161. <a href="../advanced_init/events_post_init.html">Post-init</a>
  162. </li>
  163. <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
  164. <li><a href="../advanced_init/html_sort.html">Sorting without HTML tags</a></li>
  165. <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table controls (sDom)</a></li>
  166. <li><a href="../advanced_init/length_menu.html">Defining length menu options</a></li>
  167. <li><a href="../advanced_init/complex_header.html">Complex headers and hidden columns</a></li>
  168. <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar (element) around table</a></li>
  169. <li><a href="../advanced_init/highlight.html">Row highlighting with CSS</a></li>
  170. <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
  171. <li><a href="../advanced_init/row_callback.html">Row callback</a></li>
  172. <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
  173. <li><a href="../advanced_init/sorting_control.html">Control sorting direction of columns</a></li>
  174. <li><a href="../advanced_init/language_file.html">Change language information from a file (internationalisation)</a></li>
  175. <li><a href="../advanced_init/defaults.html">Setting defaults</a></li>
  176. <li><a href="../advanced_init/localstorage.html">State saving with localStorage</a></li>
  177. <li><a href="../advanced_init/dt_events.html">Custom events</a></li>
  178. </ul>
  179. <h2>API</h2>
  180. <ul>
  181. <li><a href="../api/add_row.html">Dynamically add a new row</a></li>
  182. <li><a href="../api/multi_filter.html">Individual column filtering (using "input" elements)</a></li>
  183. <li><a href="../api/multi_filter_select.html">Individual column filtering (using "select" elements)</a></li>
  184. <li><a href="../api/highlight.html">Highlight rows and columns</a></li>
  185. <li><a href="../api/row_details.html">Show and hide details about a particular record</a></li>
  186. <li><a href="../api/select_row.html">User selectable rows (multiple rows)</a></li>
  187. <li><a href="../api/select_single_row.html">User selectable rows (single row) and delete rows</a></li>
  188. <li><a href="../api/editable.html">Editable rows (with jEditable)</a></li>
  189. <li><a href="../api/form.html">Submit form with elements in table</a></li>
  190. <li><a href="../api/counter_column.html">Index column (static number column)</a></li>
  191. <li><a href="../api/show_hide.html">Show and hide columns dynamically</a></li>
  192. <li><a href="../api/api_in_init.html">API function use in initialisation object (callback)</a></li>
  193. <li><a href="../api/tabs_and_scrolling.html">DataTables scrolling and tabs</a></li>
  194. <li><a href="../api/regex.html">Regular expression filtering</a></li>
  195. </ul>
  196. </div>
  197. <div class="demo_links">
  198. <h2>Data sources</h2>
  199. <ul>
  200. <li><a href="../data_sources/dom.html">DOM</a></li>
  201. <li><a href="../data_sources/js_array.html">Javascript array</a></li>
  202. <li><a href="../data_sources/ajax.html">Ajax source</a></li>
  203. <li><a href="../data_sources/server_side.html">Server side processing</a></li>
  204. </ul>
  205. <h2>Server-side processing</h2>
  206. <ul>
  207. <li><a href="../server_side/server_side.html">Obtain server-side data</a></li>
  208. <li><a href="../server_side/custom_vars.html">Add extra HTTP variables</a></li>
  209. <li><a href="../server_side/post.html">Use HTTP POST</a></li>
  210. <li><a href="../server_side/ids.html">Automatic addition of IDs and classes to rows</a></li>
  211. <li><a href="../server_side/object_data.html">Reading table data from objects</a></li>
  212. <li><a href="../server_side/row_details.html">Show and hide details about a particular record</a></li>
  213. <li><a href="../server_side/select_rows.html">User selectable rows (multiple rows)</a></li>
  214. <li><a href="../server_side/jsonp.html">JSONP for a cross domain data source</a></li>
  215. <li><a href="../server_side/editable.html">jEditable integration with DataTables</a></li>
  216. <li><a href="../server_side/defer_loading.html">Deferred loading of Ajax data</a></li>
  217. <li><a href="../server_side/pipeline.html">Pipelining data (reduce Ajax calls for paging)</a></li>
  218. </ul>
  219. <h2>Ajax data source</h2>
  220. <ul>
  221. <li><a href="../ajax/ajax.html">Ajax sourced data (array of arrays)</a></li>
  222. <li><a href="../ajax/objects.html">Ajax sourced data (array of objects)</a></li>
  223. <li><a href="../ajax/defer_render.html">Deferred DOM creation for extra speed</a></li>
  224. <li><a href="../ajax/null_data_source.html">Empty data source columns</a></li>
  225. <li><a href="../ajax/custom_data_property.html">Use a data source other than aaData (the default)</a></li>
  226. <li><a href="../ajax/objects_subarrays.html">Read column data from sub-arrays</a></li>
  227. <li><a href="../ajax/deep.html">Read column data from deeply nested properties</a></li>
  228. </ul>
  229. <h2>Plug-ins</h2>
  230. <ul>
  231. <li><a href="../plug-ins/plugin_api.html">Add custom API functions</a></li>
  232. <li><a href="../plug-ins/sorting_plugin.html">Sorting and automatic type detection</a></li>
  233. <li><a href="../plug-ins/sorting_sType.html">Sorting without automatic type detection</a></li>
  234. <li><a href="../plug-ins/paging_plugin.html">Custom pagination controls</a></li>
  235. <li><a href="../plug-ins/range_filtering.html">Range filtering / custom filtering</a></li>
  236. <li><a href="../plug-ins/dom_sort.html">Live DOM sorting</a></li>
  237. <li><a href="../plug-ins/html_sort.html">Automatic HTML type detection</a></li>
  238. </ul>
  239. </div>
  240. <div id="footer" class="clear" style="text-align:center;">
  241. <p>
  242. Please refer to the <a href="http://www.datatables.net/usage">DataTables documentation</a> for full information about its API properties and methods.<br>
  243. 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.
  244. </p>
  245. <span style="font-size:10px;">
  246. DataTables designed and created by <a href="http://www.sprymedia.co.uk">Allan Jardine</a> &copy; 2007-2011<br>
  247. 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>.
  248. </span>
  249. </div>
  250. </div>
  251. </body>
  252. </html>