row_details.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 - Child rows (show extra / detailed information)</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. td.details-control {
  13. background: url('../resources/details_open.png') no-repeat center center;
  14. cursor: pointer;
  15. }
  16. tr.shown td.details-control {
  17. background: url('../resources/details_close.png') no-repeat center center;
  18. }
  19. </style>
  20. <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
  21. <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
  22. <script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js"></script>
  23. <script type="text/javascript" language="javascript" src="../resources/demo.js"></script>
  24. <script type="text/javascript" language="javascript" class="init">
  25. /* Formatting function for row details - modify as you need */
  26. function format ( d ) {
  27. // `d` is the original data object for the row
  28. return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
  29. '<tr>'+
  30. '<td>Full name:</td>'+
  31. '<td>'+d.name+'</td>'+
  32. '</tr>'+
  33. '<tr>'+
  34. '<td>Extension number:</td>'+
  35. '<td>'+d.extn+'</td>'+
  36. '</tr>'+
  37. '<tr>'+
  38. '<td>Extra info:</td>'+
  39. '<td>And any further details here (images etc)...</td>'+
  40. '</tr>'+
  41. '</table>';
  42. }
  43. $(document).ready(function() {
  44. var table = $('#example').DataTable( {
  45. "ajax": "../ajax/data/objects.txt",
  46. "columns": [
  47. {
  48. "class": 'details-control',
  49. "orderable": false,
  50. "data": null,
  51. "defaultContent": ''
  52. },
  53. { "data": "name" },
  54. { "data": "position" },
  55. { "data": "office" },
  56. { "data": "salary" }
  57. ],
  58. "order": [[1, 'asc']]
  59. } );
  60. // Add event listener for opening and closing details
  61. $('#example tbody').on('click', 'td.details-control', function () {
  62. var tr = $(this).closest('tr');
  63. var row = table.row( tr );
  64. if ( row.child.isShown() ) {
  65. // This row is already open - close it
  66. row.child.hide();
  67. tr.removeClass('shown');
  68. }
  69. else {
  70. // Open this row
  71. row.child( format(row.data()) ).show();
  72. tr.addClass('shown');
  73. }
  74. } );
  75. } );
  76. </script>
  77. </head>
  78. <body class="dt-example">
  79. <div class="container">
  80. <section>
  81. <h1>DataTables example <span>Child rows (show extra / detailed information)</span></h1>
  82. <div class="info">
  83. <p>The DataTables API has a number of methods available for attaching child rows to a <em>parent</em>
  84. row in the DataTable. This can be used to show additional information about a row, useful for cases
  85. where you wish to convey more information about a row than there is space for in the host table.</p>
  86. <p>The example below makes use of the <a href="//datatables.net/reference/api/row().child"><code class=
  87. "api" title="DataTables API method">row().child<span>DT</span></code></a> methods to firstly check if a
  88. row is already displayed, and if so hide it (<a href=
  89. "//datatables.net/reference/api/row().child.hide()"><code class="api" title=
  90. "DataTables API method">row().child.hide()<span>DT</span></code></a>), otherwise show it (<a href=
  91. "//datatables.net/reference/api/row().child.show()"><code class="api" title=
  92. "DataTables API method">row().child.show()<span>DT</span></code></a>). The content of the child row is,
  93. in this example, defined by the <code>formatDetails()</code> function, but you would replace that with
  94. whatever you wanted to show the content required, possibly including, for example, an Ajax call to the
  95. server to obtain the extra information to show.</p>
  96. </div>
  97. <table id="example" class="display" cellspacing="0" width="100%">
  98. <thead>
  99. <tr>
  100. <th></th>
  101. <th>Name</th>
  102. <th>Position</th>
  103. <th>Office</th>
  104. <th>Salary</th>
  105. </tr>
  106. </thead>
  107. <tfoot>
  108. <tr>
  109. <th></th>
  110. <th>Name</th>
  111. <th>Position</th>
  112. <th>Office</th>
  113. <th>Salary</th>
  114. </tr>
  115. </tfoot>
  116. </table>
  117. <ul class="tabs">
  118. <li class="active">Javascript</li>
  119. <li>HTML</li>
  120. <li>CSS</li>
  121. <li>Ajax</li>
  122. <li>Server-side script</li>
  123. </ul>
  124. <div class="tabs">
  125. <div class="js">
  126. <p>The Javascript shown below is used to initialise the table shown in this
  127. example:</p><code class="multiline brush: js;">/* Formatting function for row details - modify as you need */
  128. function format ( d ) {
  129. // `d` is the original data object for the row
  130. return '&lt;table cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; style=&quot;padding-left:50px;&quot;&gt;'+
  131. '&lt;tr&gt;'+
  132. '&lt;td&gt;Full name:&lt;/td&gt;'+
  133. '&lt;td&gt;'+d.name+'&lt;/td&gt;'+
  134. '&lt;/tr&gt;'+
  135. '&lt;tr&gt;'+
  136. '&lt;td&gt;Extension number:&lt;/td&gt;'+
  137. '&lt;td&gt;'+d.extn+'&lt;/td&gt;'+
  138. '&lt;/tr&gt;'+
  139. '&lt;tr&gt;'+
  140. '&lt;td&gt;Extra info:&lt;/td&gt;'+
  141. '&lt;td&gt;And any further details here (images etc)...&lt;/td&gt;'+
  142. '&lt;/tr&gt;'+
  143. '&lt;/table&gt;';
  144. }
  145. $(document).ready(function() {
  146. var table = $('#example').DataTable( {
  147. &quot;ajax&quot;: &quot;../ajax/data/objects.txt&quot;,
  148. &quot;columns&quot;: [
  149. {
  150. &quot;class&quot;: 'details-control',
  151. &quot;orderable&quot;: false,
  152. &quot;data&quot;: null,
  153. &quot;defaultContent&quot;: ''
  154. },
  155. { &quot;data&quot;: &quot;name&quot; },
  156. { &quot;data&quot;: &quot;position&quot; },
  157. { &quot;data&quot;: &quot;office&quot; },
  158. { &quot;data&quot;: &quot;salary&quot; }
  159. ],
  160. &quot;order&quot;: [[1, 'asc']]
  161. } );
  162. // Add event listener for opening and closing details
  163. $('#example tbody').on('click', 'td.details-control', function () {
  164. var tr = $(this).closest('tr');
  165. var row = table.row( tr );
  166. if ( row.child.isShown() ) {
  167. // This row is already open - close it
  168. row.child.hide();
  169. tr.removeClass('shown');
  170. }
  171. else {
  172. // Open this row
  173. row.child( format(row.data()) ).show();
  174. tr.addClass('shown');
  175. }
  176. } );
  177. } );</code>
  178. <p>In addition to the above code, the following Javascript library files are loaded for use in this
  179. example:</p>
  180. <ul>
  181. <li><a href="../../media/js/jquery.js">../../media/js/jquery.js</a></li>
  182. <li><a href="../../media/js/jquery.dataTables.js">../../media/js/jquery.dataTables.js</a></li>
  183. </ul>
  184. </div>
  185. <div class="table">
  186. <p>The HTML shown below is the raw HTML table element, before it has been enhanced by
  187. DataTables:</p>
  188. </div>
  189. <div class="css">
  190. <div>
  191. <p>This example uses a little bit of additional CSS beyond what is loaded from the library
  192. files (below), in order to correctly display the table. The additional CSS used is shown
  193. below:</p><code class="multiline brush: js;">td.details-control {
  194. background: url('../resources/details_open.png') no-repeat center center;
  195. cursor: pointer;
  196. }
  197. tr.shown td.details-control {
  198. background: url('../resources/details_close.png') no-repeat center center;
  199. }</code>
  200. </div>
  201. <p>The following CSS library files are loaded for use in this example to provide the styling of the
  202. table:</p>
  203. <ul>
  204. <li><a href=
  205. "../../media/css/jquery.dataTables.css">../../media/css/jquery.dataTables.css</a></li>
  206. </ul>
  207. </div>
  208. <div class="ajax">
  209. <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
  210. will update automatically as any additional data is loaded.</p>
  211. </div>
  212. <div class="php">
  213. <p>The script used to perform the server-side processing for this table is shown below. Please note
  214. that this is just an example script using PHP. Server-side processing scripts can be written in any
  215. language, using <a href="//datatables.net/manual/server-side">the protocol described in the
  216. DataTables documentation</a>.</p>
  217. </div>
  218. </div>
  219. </section>
  220. </div>
  221. <section>
  222. <div class="footer">
  223. <div class="gradient"></div>
  224. <div class="liner">
  225. <h2>Other examples</h2>
  226. <div class="toc">
  227. <div class="toc-group">
  228. <h3><a href="../basic_init/index.html">Basic initialisation</a></h3>
  229. <ul class="toc">
  230. <li><a href="../basic_init/zero_configuration.html">Zero configuration</a></li>
  231. <li><a href="../basic_init/filter_only.html">Feature enable / disable</a></li>
  232. <li><a href="../basic_init/table_sorting.html">Default ordering (sorting)</a></li>
  233. <li><a href="../basic_init/multi_col_sort.html">Multi-column ordering</a></li>
  234. <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
  235. <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
  236. <li><a href="../basic_init/complex_header.html">Complex headers (rowspan and
  237. colspan)</a></li>
  238. <li><a href="../basic_init/dom.html">DOM positioning</a></li>
  239. <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li>
  240. <li><a href="../basic_init/state_save.html">State saving</a></li>
  241. <li><a href="../basic_init/alt_pagination.html">Alternative pagination</a></li>
  242. <li><a href="../basic_init/scroll_y.html">Scroll - vertical</a></li>
  243. <li><a href="../basic_init/scroll_x.html">Scroll - horizontal</a></li>
  244. <li><a href="../basic_init/scroll_xy.html">Scroll - horizontal and vertical</a></li>
  245. <li><a href="../basic_init/scroll_y_theme.html">Scroll - vertical with jQuery UI
  246. ThemeRoller</a></li>
  247. <li><a href="../basic_init/comma-decimal.html">Language - Comma decimal place</a></li>
  248. <li><a href="../basic_init/language.html">Language options</a></li>
  249. </ul>
  250. </div>
  251. <div class="toc-group">
  252. <h3><a href="../advanced_init/index.html">Advanced initialisation</a></h3>
  253. <ul class="toc">
  254. <li><a href="../advanced_init/events_live.html">DOM / jQuery events</a></li>
  255. <li><a href="../advanced_init/dt_events.html">DataTables events</a></li>
  256. <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
  257. <li><a href="../advanced_init/length_menu.html">Page length options</a></li>
  258. <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table control
  259. elements</a></li>
  260. <li><a href="../advanced_init/complex_header.html">Complex headers (rowspan /
  261. colspan)</a></li>
  262. <li><a href="../advanced_init/html5-data-attributes.html">HTML5 data-* attributes</a></li>
  263. <li><a href="../advanced_init/language_file.html">Language file</a></li>
  264. <li><a href="../advanced_init/defaults.html">Setting defaults</a></li>
  265. <li><a href="../advanced_init/row_callback.html">Row created callback</a></li>
  266. <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
  267. <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
  268. <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar elements</a></li>
  269. <li><a href="../advanced_init/sort_direction_control.html">Order direction sequence
  270. control</a></li>
  271. </ul>
  272. </div>
  273. <div class="toc-group">
  274. <h3><a href="../styling/index.html">Styling</a></h3>
  275. <ul class="toc">
  276. <li><a href="../styling/display.html">Base style</a></li>
  277. <li><a href="../styling/no-classes.html">Base style - no styling classes</a></li>
  278. <li><a href="../styling/cell-border.html">Base style - cell borders</a></li>
  279. <li><a href="../styling/compact.html">Base style - compact</a></li>
  280. <li><a href="../styling/hover.html">Base style - hover</a></li>
  281. <li><a href="../styling/order-column.html">Base style - order-column</a></li>
  282. <li><a href="../styling/row-border.html">Base style - row borders</a></li>
  283. <li><a href="../styling/stripe.html">Base style - stripe</a></li>
  284. <li><a href="../styling/bootstrap.html">Bootstrap</a></li>
  285. <li><a href="../styling/foundation.html">Foundation</a></li>
  286. <li><a href="../styling/jqueryUI.html">jQuery UI ThemeRoller</a></li>
  287. </ul>
  288. </div>
  289. <div class="toc-group">
  290. <h3><a href="../data_sources/index.html">Data sources</a></h3>
  291. <ul class="toc">
  292. <li><a href="../data_sources/dom.html">HTML (DOM) sourced data</a></li>
  293. <li><a href="../data_sources/ajax.html">Ajax sourced data</a></li>
  294. <li><a href="../data_sources/js_array.html">Javascript sourced data</a></li>
  295. <li><a href="../data_sources/server_side.html">Server-side processing</a></li>
  296. </ul>
  297. </div>
  298. <div class="toc-group">
  299. <h3><a href="./index.html">API</a></h3>
  300. <ul class="toc active">
  301. <li><a href="./add_row.html">Add rows</a></li>
  302. <li><a href="./multi_filter.html">Individual column searching (text inputs)</a></li>
  303. <li><a href="./multi_filter_select.html">Individual column searching (select
  304. inputs)</a></li>
  305. <li><a href="./highlight.html">Highlighting rows and columns</a></li>
  306. <li class="active"><a href="./row_details.html">Child rows (show extra / detailed
  307. information)</a></li>
  308. <li><a href="./select_row.html">Row selection (multiple rows)</a></li>
  309. <li><a href="./select_single_row.html">Row selection and deletion (single row)</a></li>
  310. <li><a href="./form.html">Form inputs</a></li>
  311. <li><a href="./counter_columns.html">Index column</a></li>
  312. <li><a href="./show_hide.html">Show / hide columns dynamically</a></li>
  313. <li><a href="./api_in_init.html">Using API in callbacks</a></li>
  314. <li><a href="./tabs_and_scrolling.html">Scrolling and jQuery UI tabs</a></li>
  315. <li><a href="./regex.html">Search API (regular expressions)</a></li>
  316. </ul>
  317. </div>
  318. <div class="toc-group">
  319. <h3><a href="../ajax/index.html">Ajax</a></h3>
  320. <ul class="toc">
  321. <li><a href="../ajax/simple.html">Ajax data source (arrays)</a></li>
  322. <li><a href="../ajax/objects.html">Ajax data source (objects)</a></li>
  323. <li><a href="../ajax/deep.html">Nested object data (objects)</a></li>
  324. <li><a href="../ajax/objects_subarrays.html">Nested object data (arrays)</a></li>
  325. <li><a href="../ajax/orthogonal-data.html">Orthogonal data</a></li>
  326. <li><a href="../ajax/null_data_source.html">Generated content for a column</a></li>
  327. <li><a href="../ajax/custom_data_property.html">Custom data source property</a></li>
  328. <li><a href="../ajax/custom_data_flat.html">Flat array data source</a></li>
  329. <li><a href="../ajax/defer_render.html">Deferred rendering for speed</a></li>
  330. </ul>
  331. </div>
  332. <div class="toc-group">
  333. <h3><a href="../server_side/index.html">Server-side</a></h3>
  334. <ul class="toc">
  335. <li><a href="../server_side/simple.html">Server-side processing</a></li>
  336. <li><a href="../server_side/custom_vars.html">Custom HTTP variables</a></li>
  337. <li><a href="../server_side/post.html">POST data</a></li>
  338. <li><a href="../server_side/ids.html">Automatic addition of row ID attributes</a></li>
  339. <li><a href="../server_side/object_data.html">Object data source</a></li>
  340. <li><a href="../server_side/row_details.html">Row details</a></li>
  341. <li><a href="../server_side/select_rows.html">Row selection</a></li>
  342. <li><a href="../server_side/jsonp.html">JSONP data source for remote domains</a></li>
  343. <li><a href="../server_side/defer_loading.html">Deferred loading of data</a></li>
  344. <li><a href="../server_side/pipeline.html">Pipelining data to reduce Ajax calls for
  345. paging</a></li>
  346. </ul>
  347. </div>
  348. <div class="toc-group">
  349. <h3><a href="../plug-ins/index.html">Plug-ins</a></h3>
  350. <ul class="toc">
  351. <li><a href="../plug-ins/api.html">API plug-in methods</a></li>
  352. <li><a href="../plug-ins/sorting_auto.html">Ordering plug-ins (with type
  353. detection)</a></li>
  354. <li><a href="../plug-ins/sorting_manual.html">Ordering plug-ins (no type
  355. detection)</a></li>
  356. <li><a href="../plug-ins/range_filtering.html">Custom filtering - range search</a></li>
  357. <li><a href="../plug-ins/dom_sort.html">Live DOM ordering</a></li>
  358. </ul>
  359. </div>
  360. </div>
  361. <div class="epilogue">
  362. <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
  363. information about its API properties and methods.<br>
  364. Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
  365. <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
  366. DataTables.</p>
  367. <p class="copyright">DataTables designed and created by <a href=
  368. "http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2014<br>
  369. DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
  370. </div>
  371. </div>
  372. </div>
  373. </section>
  374. </body>
  375. </html>