Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

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