object_data.html 14 KB

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