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