Project

General

Profile

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>ColVis example - Two tables with shared controls</title>
9
	<link rel="stylesheet" type="text/css" href="../../../media/css/jquery.dataTables.css">
10
	<link rel="stylesheet" type="text/css" href="../css/dataTables.colVis.css">
11
	<link rel="stylesheet" type="text/css" href="../../../examples/resources/syntax/shCore.css">
12
	<link rel="stylesheet" type="text/css" href="../../../examples/resources/demo.css">
13
	<style type="text/css" class="init">
14

    
15
	</style>
16
	<script type="text/javascript" language="javascript" src="../../../media/js/jquery.js"></script>
17
	<script type="text/javascript" language="javascript" src="../../../media/js/jquery.dataTables.js"></script>
18
	<script type="text/javascript" language="javascript" src="../js/dataTables.colVis.js"></script>
19
	<script type="text/javascript" language="javascript" src="../../../examples/resources/syntax/shCore.js"></script>
20
	<script type="text/javascript" language="javascript" src="../../../examples/resources/demo.js"></script>
21
	<script type="text/javascript" language="javascript" class="init">
22

    
23

    
24
$(document).ready(function() {
25
	var tables = $('table.display').DataTable( {
26
		displayLength: 5
27
	} );
28

    
29
	// When the column visibility changes on the firs table, also change it on
30
	// the others
31
	tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
32
		tables.tables(':gt(0)').column( colIdx ).visible( visibility );
33
	} );
34

    
35
	// Create ColVis on the first table only
36
	var colvis = new $.fn.dataTable.ColVis( tables.table(0) );
37
	$( colvis.button() ).insertAfter('div.info');
38
} );
39

    
40

    
41
	</script>
42
</head>
43

    
44
<body class="dt-example">
45
	<div class="container">
46
		<section>
47
			<h1>ColVis example <span>Two tables with shared controls</span></h1>
48

    
49
			<div class="info">
50
				<p>This example shows how the DataTables API can be used with ColVis to use a single ColVis control to
51
				effect other tables. This is done by applying ColVis to the first table and then listening for the
52
				<a href="//datatables.net/reference/event/column-visibility"><code class="event" title=
53
				"DataTables event">column-visibility<span>DT</span></code></a> event and updating all other tables when
54
				triggered.</p>
55

    
56
				<p>This example makes use of the <a href="//datatables.net/reference/api/tables()"><code class="api"
57
				title="DataTables API method">tables()<span>DT</span></code></a> and <a href=
58
				"//datatables.net/reference/api/table()"><code class="api" title=
59
				"DataTables API method">table()<span>DT</span></code></a> methods for working with multiple tables, and
60
				also initialised ColVis using the <code>new $.fn.dataTable.ColVis();</code> operator.</p>
61
			</div>
62

    
63
			<table id="" class="display" cellspacing="0" width="100%">
64
				<thead>
65
					<tr>
66
						<th>Name</th>
67
						<th>Position</th>
68
						<th>Office</th>
69
						<th>Age</th>
70
						<th>Salary</th>
71
					</tr>
72
				</thead>
73

    
74
				<tfoot>
75
					<tr>
76
						<th>Name</th>
77
						<th>Position</th>
78
						<th>Office</th>
79
						<th>Age</th>
80
						<th>Salary</th>
81
					</tr>
82
				</tfoot>
83

    
84
				<tbody>
85
					<tr>
86
						<td>Tiger Nixon</td>
87
						<td>System Architect</td>
88
						<td>Edinburgh</td>
89
						<td>61</td>
90
						<td>$320,800</td>
91
					</tr>
92
					<tr>
93
						<td>Cedric Kelly</td>
94
						<td>Senior Javascript Developer</td>
95
						<td>Edinburgh</td>
96
						<td>22</td>
97
						<td>$433,060</td>
98
					</tr>
99
					<tr>
100
						<td>Sonya Frost</td>
101
						<td>Software Engineer</td>
102
						<td>Edinburgh</td>
103
						<td>23</td>
104
						<td>$103,600</td>
105
					</tr>
106
					<tr>
107
						<td>Quinn Flynn</td>
108
						<td>Support Lead</td>
109
						<td>Edinburgh</td>
110
						<td>22</td>
111
						<td>$342,000</td>
112
					</tr>
113
					<tr>
114
						<td>Dai Rios</td>
115
						<td>Personnel Lead</td>
116
						<td>Edinburgh</td>
117
						<td>35</td>
118
						<td>$217,500</td>
119
					</tr>
120
					<tr>
121
						<td>Gavin Joyce</td>
122
						<td>Developer</td>
123
						<td>Edinburgh</td>
124
						<td>42</td>
125
						<td>$92,575</td>
126
					</tr>
127
					<tr>
128
						<td>Martena Mccray</td>
129
						<td>Post-Sales support</td>
130
						<td>Edinburgh</td>
131
						<td>46</td>
132
						<td>$324,050</td>
133
					</tr>
134
					<tr>
135
						<td>Jennifer Acosta</td>
136
						<td>Junior Javascript Developer</td>
137
						<td>Edinburgh</td>
138
						<td>43</td>
139
						<td>$75,650</td>
140
					</tr>
141
					<tr>
142
						<td>Shad Decker</td>
143
						<td>Regional Director</td>
144
						<td>Edinburgh</td>
145
						<td>51</td>
146
						<td>$183,000</td>
147
					</tr>
148
				</tbody>
149
			</table>
150

    
151
			<table id="" class="display" cellspacing="0" width="100%">
152
				<thead>
153
					<tr>
154
						<th>Name</th>
155
						<th>Position</th>
156
						<th>Office</th>
157
						<th>Age</th>
158
						<th>Salary</th>
159
					</tr>
160
				</thead>
161

    
162
				<tfoot>
163
					<tr>
164
						<th>Name</th>
165
						<th>Position</th>
166
						<th>Office</th>
167
						<th>Age</th>
168
						<th>Salary</th>
169
					</tr>
170
				</tfoot>
171

    
172
				<tbody>
173
					<tr>
174
						<td>Jena Gaines</td>
175
						<td>Office Manager</td>
176
						<td>London</td>
177
						<td>30</td>
178
						<td>$90,560</td>
179
					</tr>
180
					<tr>
181
						<td>Haley Kennedy</td>
182
						<td>Senior Marketing Designer</td>
183
						<td>London</td>
184
						<td>43</td>
185
						<td>$313,500</td>
186
					</tr>
187
					<tr>
188
						<td>Tatyana Fitzpatrick</td>
189
						<td>Regional Director</td>
190
						<td>London</td>
191
						<td>19</td>
192
						<td>$385,750</td>
193
					</tr>
194
					<tr>
195
						<td>Michael Silva</td>
196
						<td>Marketing Designer</td>
197
						<td>London</td>
198
						<td>66</td>
199
						<td>$198,500</td>
200
					</tr>
201
					<tr>
202
						<td>Bradley Greer</td>
203
						<td>Software Engineer</td>
204
						<td>London</td>
205
						<td>41</td>
206
						<td>$132,000</td>
207
					</tr>
208
					<tr>
209
						<td>Angelica Ramos</td>
210
						<td>Chief Executive Officer (CEO)</td>
211
						<td>London</td>
212
						<td>47</td>
213
						<td>$1,200,000</td>
214
					</tr>
215
					<tr>
216
						<td>Suki Burks</td>
217
						<td>Developer</td>
218
						<td>London</td>
219
						<td>53</td>
220
						<td>$114,500</td>
221
					</tr>
222
					<tr>
223
						<td>Prescott Bartlett</td>
224
						<td>Technical Author</td>
225
						<td>London</td>
226
						<td>27</td>
227
						<td>$145,000</td>
228
					</tr>
229
					<tr>
230
						<td>Timothy Mooney</td>
231
						<td>Office Manager</td>
232
						<td>London</td>
233
						<td>37</td>
234
						<td>$136,200</td>
235
					</tr>
236
					<tr>
237
						<td>Bruno Nash</td>
238
						<td>Software Engineer</td>
239
						<td>London</td>
240
						<td>38</td>
241
						<td>$163,500</td>
242
					</tr>
243
					<tr>
244
						<td>Hermione Butler</td>
245
						<td>Regional Director</td>
246
						<td>London</td>
247
						<td>47</td>
248
						<td>$356,250</td>
249
					</tr>
250
					<tr>
251
						<td>Lael Greer</td>
252
						<td>Systems Administrator</td>
253
						<td>London</td>
254
						<td>21</td>
255
						<td>$103,500</td>
256
					</tr>
257
				</tbody>
258
			</table>
259

    
260
			<ul class="tabs">
261
				<li class="active">Javascript</li>
262
				<li>HTML</li>
263
				<li>CSS</li>
264
				<li>Ajax</li>
265
				<li>Server-side script</li>
266
			</ul>
267

    
268
			<div class="tabs">
269
				<div class="js">
270
					<p>The Javascript shown below is used to initialise the table shown in this
271
					example:</p><code class="multiline brush: js;">$(document).ready(function() {
272
	var tables = $('table.display').DataTable( {
273
		displayLength: 5
274
	} );
275

    
276
	// When the column visibility changes on the firs table, also change it on
277
	// the others
278
	tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
279
		tables.tables(':gt(0)').column( colIdx ).visible( visibility );
280
	} );
281

    
282
	// Create ColVis on the first table only
283
	var colvis = new $.fn.dataTable.ColVis( tables.table(0) );
284
	$( colvis.button() ).insertAfter('div.info');
285
} );</code>
286

    
287
					<p>In addition to the above code, the following Javascript library files are loaded for use in this
288
					example:</p>
289

    
290
					<ul>
291
						<li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
292
						<li><a href=
293
						"../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
294
						<li><a href="../js/dataTables.colVis.js">../js/dataTables.colVis.js</a></li>
295
					</ul>
296
				</div>
297

    
298
				<div class="table">
299
					<p>The HTML shown below is the raw HTML table element, before it has been enhanced by
300
					DataTables:</p>
301
				</div>
302

    
303
				<div class="css">
304
					<div>
305
						<p>This example uses a little bit of additional CSS beyond what is loaded from the library
306
						files (below), in order to correctly display the table. The additional CSS used is shown
307
						below:</p><code class="multiline brush: js;"></code>
308
					</div>
309

    
310
					<p>The following CSS library files are loaded for use in this example to provide the styling of the
311
					table:</p>
312

    
313
					<ul>
314
						<li><a href=
315
						"../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
316
						<li><a href="../css/dataTables.colVis.css">../css/dataTables.colVis.css</a></li>
317
					</ul>
318
				</div>
319

    
320
				<div class="ajax">
321
					<p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
322
					will update automatically as any additional data is loaded.</p>
323
				</div>
324

    
325
				<div class="php">
326
					<p>The script used to perform the server-side processing for this table is shown below. Please note
327
					that this is just an example script using PHP. Server-side processing scripts can be written in any
328
					language, using <a href="//datatables.net/manual/server-side">the protocol described in the
329
					DataTables documentation</a>.</p>
330
				</div>
331
			</div>
332
		</section>
333
	</div>
334

    
335
	<section>
336
		<div class="footer">
337
			<div class="gradient"></div>
338

    
339
			<div class="liner">
340
				<h2>Other examples</h2>
341

    
342
				<div class="toc">
343
					<div class="toc-group">
344
						<h3><a href="./index.html">Examples</a></h3>
345
						<ul class="toc active">
346
							<li><a href="./simple.html">Basic initialisation</a></li>
347
							<li><a href="./new_init.html">`new` initialisation</a></li>
348
							<li><a href="./text.html">Custom button text</a></li>
349
							<li><a href="./exclude_columns.html">Exclude columns from list</a></li>
350
							<li><a href="./title_callback.html">Column button callback</a></li>
351
							<li><a href="./button_order.html">Button ordering</a></li>
352
							<li><a href="./mouseover.html">Mouseover activation</a></li>
353
							<li><a href="./group_columns.html">Group columns</a></li>
354
							<li><a href="./two_tables.html">Two tables with individual controls</a></li>
355
							<li class="active"><a href="./two_tables_identical.html">Two tables with shared
356
							controls</a></li>
357
							<li><a href="./restore.html">Restore / show all</a></li>
358
							<li><a href="./jqueryui.html">jQuery UI styling</a></li>
359
						</ul>
360
					</div>
361
				</div>
362

    
363
				<div class="epilogue">
364
					<p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
365
					information about its API properties and methods.<br>
366
					Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
367
					<a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
368
					DataTables.</p>
369

    
370
					<p class="copyright">DataTables designed and created by <a href=
371
					"http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2014<br>
372
					DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
373
				</div>
374
			</div>
375
		</div>
376
	</section>
377
</body>
378
</html>
(13-13/13)