Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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