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">
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">
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">
24 $(document).ready(function() {
25 var tables = $('table.display').DataTable( {
29 // When the column visibility changes on the firs table, also change it on
31 tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
32 tables.tables(':gt(0)').column( colIdx ).visible( visibility );
35 // Create ColVis on the first table only
36 var colvis = new $.fn.dataTable.ColVis( tables.table(0) );
37 $( colvis.button() ).insertAfter('div.info');
44 <body class="dt-example">
45 <div class="container">
47 <h1>ColVis example <span>Two tables with shared controls</span></h1>
50 <p>This example shows how the DataTables API can be used with ColVis to use a single ColVis control to effect other tables. This is done by applying ColVis to the
51 first table and then listening for the <a href="//datatables.net/reference/event/column-visibility"><code class="event" title=
52 "DataTables event">column-visibility<span>DT</span></code></a> event and updating all other tables when triggered.</p>
54 <p>This example makes use of the <a href="//datatables.net/reference/api/tables()"><code class="api" title=
55 "DataTables API method">tables()<span>DT</span></code></a> and <a href="//datatables.net/reference/api/table()"><code class="api" title=
56 "DataTables API method">table()<span>DT</span></code></a> methods for working with multiple tables, and also initialised ColVis using the <code>new
57 $.fn.dataTable.ColVis();</code> operator.</p>
60 <table id="" class="display" cellspacing="0" width="100%">
84 <td>System Architect</td>
91 <td>Senior Javascript Developer</td>
98 <td>Software Engineer</td>
105 <td>Support Lead</td>
112 <td>Personnel Lead</td>
125 <td>Martena Mccray</td>
126 <td>Post-Sales support</td>
132 <td>Jennifer Acosta</td>
133 <td>Junior Javascript Developer</td>
140 <td>Regional Director</td>
148 <table id="" class="display" cellspacing="0" width="100%">
172 <td>Office Manager</td>
178 <td>Haley Kennedy</td>
179 <td>Senior Marketing Designer</td>
185 <td>Tatyana Fitzpatrick</td>
186 <td>Regional Director</td>
192 <td>Michael Silva</td>
193 <td>Marketing Designer</td>
199 <td>Bradley Greer</td>
200 <td>Software Engineer</td>
206 <td>Angelica Ramos</td>
207 <td>Chief Executive Officer (CEO)</td>
220 <td>Prescott Bartlett</td>
221 <td>Technical Author</td>
227 <td>Timothy Mooney</td>
228 <td>Office Manager</td>
235 <td>Software Engineer</td>
241 <td>Hermione Butler</td>
242 <td>Regional Director</td>
249 <td>Systems Administrator</td>
258 <li class="active">Javascript</li>
262 <li>Server-side script</li>
267 <p>The Javascript shown below is used to initialise the table shown in this example:</p><code class="multiline language-js">$(document).ready(function() {
268 var tables = $('table.display').DataTable( {
272 // When the column visibility changes on the firs table, also change it on
274 tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
275 tables.tables(':gt(0)').column( colIdx ).visible( visibility );
278 // Create ColVis on the first table only
279 var colvis = new $.fn.dataTable.ColVis( tables.table(0) );
280 $( colvis.button() ).insertAfter('div.info');
283 <p>In addition to the above code, the following Javascript library files are loaded for use in this example:</p>
286 <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
287 <li><a href="../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
288 <li><a href="../js/dataTables.colVis.js">../js/dataTables.colVis.js</a></li>
293 <p>The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:</p>
298 <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
299 additional CSS used is shown below:</p><code class="multiline language-css"></code>
302 <p>The following CSS library files are loaded for use in this example to provide the styling of the table:</p>
305 <li><a href="../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
306 <li><a href="../css/dataTables.colVis.css">../css/dataTables.colVis.css</a></li>
311 <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
316 <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
317 processing scripts can be written in any language, using <a href="//datatables.net/manual/server-side">the protocol described in the DataTables
318 documentation</a>.</p>
326 <div class="gradient"></div>
329 <h2>Other examples</h2>
332 <div class="toc-group">
333 <h3><a href="./index.html">Examples</a></h3>
334 <ul class="toc active">
335 <li><a href="./simple.html">Basic initialisation</a></li>
336 <li><a href="./new_init.html">`new` initialisation</a></li>
337 <li><a href="./text.html">Custom button text</a></li>
338 <li><a href="./exclude_columns.html">Exclude columns from list</a></li>
339 <li><a href="./title_callback.html">Column button callback</a></li>
340 <li><a href="./button_order.html">Button ordering</a></li>
341 <li><a href="./mouseover.html">Mouseover activation</a></li>
342 <li><a href="./group_columns.html">Group columns</a></li>
343 <li><a href="./two_tables.html">Two tables with individual controls</a></li>
344 <li class="active"><a href="./two_tables_identical.html">Two tables with shared controls</a></li>
345 <li><a href="./restore.html">Restore / show all</a></li>
346 <li><a href="./jqueryui.html">jQuery UI styling</a></li>
351 <div class="epilogue">
352 <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full information about its API properties and methods.<br>
353 Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and <a href="http://www.datatables.net/plug-ins">plug-ins</a>
354 which extend the capabilities of DataTables.</p>
356 <p class="copyright">DataTables designed and created by <a href="http://www.sprymedia.co.uk">SpryMedia Ltd</a> © 2007-2015<br>
357 DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>