two_tables_identical.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. <title>ColVis example - Two tables with shared controls</title>
  8. <link rel="stylesheet" type="text/css" href="../../../media/css/jquery.dataTables.css">
  9. <link rel="stylesheet" type="text/css" href="../css/dataTables.colVis.css">
  10. <link rel="stylesheet" type="text/css" href="../../../examples/resources/syntax/shCore.css">
  11. <link rel="stylesheet" type="text/css" href="../../../examples/resources/demo.css">
  12. <style type="text/css" class="init">
  13. </style>
  14. <script type="text/javascript" language="javascript" src="../../../media/js/jquery.js"></script>
  15. <script type="text/javascript" language="javascript" src="../../../media/js/jquery.dataTables.js"></script>
  16. <script type="text/javascript" language="javascript" src="../js/dataTables.colVis.js"></script>
  17. <script type="text/javascript" language="javascript" src="../../../examples/resources/syntax/shCore.js"></script>
  18. <script type="text/javascript" language="javascript" src="../../../examples/resources/demo.js"></script>
  19. <script type="text/javascript" language="javascript" class="init">
  20. $(document).ready(function() {
  21. var tables = $('table.display').DataTable( {
  22. displayLength: 5
  23. } );
  24. // When the column visibility changes on the firs table, also change it on
  25. // the others
  26. tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
  27. tables.tables(':gt(0)').column( colIdx ).visible( visibility );
  28. } );
  29. // Create ColVis on the first table only
  30. var colvis = new $.fn.dataTable.ColVis( tables.table(0) );
  31. $( colvis.button() ).insertAfter('div.info');
  32. } );
  33. </script>
  34. </head>
  35. <body class="dt-example">
  36. <div class="container">
  37. <section>
  38. <h1>ColVis example <span>Two tables with shared controls</span></h1>
  39. <div class="info">
  40. <p>This example shows how the DataTables API can be used with ColVis to use a single ColVis control to
  41. effect other tables. This is done by applying ColVis to the first table and then listening for the
  42. <a href="//datatables.net/reference/event/column-visibility"><code class="event" title=
  43. "DataTables event">column-visibility<span>DT</span></code></a> event and updating all other tables when
  44. triggered.</p>
  45. <p>This example makes use of the <a href="//datatables.net/reference/api/tables()"><code class="api"
  46. title="DataTables API method">tables()<span>DT</span></code></a> and <a href=
  47. "//datatables.net/reference/api/table()"><code class="api" title=
  48. "DataTables API method">table()<span>DT</span></code></a> methods for working with multiple tables, and
  49. also initialised ColVis using the <code>new $.fn.dataTable.ColVis();</code> operator.</p>
  50. </div>
  51. <table id="" class="display" cellspacing="0" width="100%">
  52. <thead>
  53. <tr>
  54. <th>Name</th>
  55. <th>Position</th>
  56. <th>Office</th>
  57. <th>Age</th>
  58. <th>Salary</th>
  59. </tr>
  60. </thead>
  61. <tfoot>
  62. <tr>
  63. <th>Name</th>
  64. <th>Position</th>
  65. <th>Office</th>
  66. <th>Age</th>
  67. <th>Salary</th>
  68. </tr>
  69. </tfoot>
  70. <tbody>
  71. <tr>
  72. <td>Tiger Nixon</td>
  73. <td>System Architect</td>
  74. <td>Edinburgh</td>
  75. <td>61</td>
  76. <td>$320,800</td>
  77. </tr>
  78. <tr>
  79. <td>Cedric Kelly</td>
  80. <td>Senior Javascript Developer</td>
  81. <td>Edinburgh</td>
  82. <td>22</td>
  83. <td>$433,060</td>
  84. </tr>
  85. <tr>
  86. <td>Sonya Frost</td>
  87. <td>Software Engineer</td>
  88. <td>Edinburgh</td>
  89. <td>23</td>
  90. <td>$103,600</td>
  91. </tr>
  92. <tr>
  93. <td>Quinn Flynn</td>
  94. <td>Support Lead</td>
  95. <td>Edinburgh</td>
  96. <td>22</td>
  97. <td>$342,000</td>
  98. </tr>
  99. <tr>
  100. <td>Dai Rios</td>
  101. <td>Personnel Lead</td>
  102. <td>Edinburgh</td>
  103. <td>35</td>
  104. <td>$217,500</td>
  105. </tr>
  106. <tr>
  107. <td>Gavin Joyce</td>
  108. <td>Developer</td>
  109. <td>Edinburgh</td>
  110. <td>42</td>
  111. <td>$92,575</td>
  112. </tr>
  113. <tr>
  114. <td>Martena Mccray</td>
  115. <td>Post-Sales support</td>
  116. <td>Edinburgh</td>
  117. <td>46</td>
  118. <td>$324,050</td>
  119. </tr>
  120. <tr>
  121. <td>Jennifer Acosta</td>
  122. <td>Junior Javascript Developer</td>
  123. <td>Edinburgh</td>
  124. <td>43</td>
  125. <td>$75,650</td>
  126. </tr>
  127. <tr>
  128. <td>Shad Decker</td>
  129. <td>Regional Director</td>
  130. <td>Edinburgh</td>
  131. <td>51</td>
  132. <td>$183,000</td>
  133. </tr>
  134. </tbody>
  135. </table>
  136. <table id="" class="display" cellspacing="0" width="100%">
  137. <thead>
  138. <tr>
  139. <th>Name</th>
  140. <th>Position</th>
  141. <th>Office</th>
  142. <th>Age</th>
  143. <th>Salary</th>
  144. </tr>
  145. </thead>
  146. <tfoot>
  147. <tr>
  148. <th>Name</th>
  149. <th>Position</th>
  150. <th>Office</th>
  151. <th>Age</th>
  152. <th>Salary</th>
  153. </tr>
  154. </tfoot>
  155. <tbody>
  156. <tr>
  157. <td>Jena Gaines</td>
  158. <td>Office Manager</td>
  159. <td>London</td>
  160. <td>30</td>
  161. <td>$90,560</td>
  162. </tr>
  163. <tr>
  164. <td>Haley Kennedy</td>
  165. <td>Senior Marketing Designer</td>
  166. <td>London</td>
  167. <td>43</td>
  168. <td>$313,500</td>
  169. </tr>
  170. <tr>
  171. <td>Tatyana Fitzpatrick</td>
  172. <td>Regional Director</td>
  173. <td>London</td>
  174. <td>19</td>
  175. <td>$385,750</td>
  176. </tr>
  177. <tr>
  178. <td>Michael Silva</td>
  179. <td>Marketing Designer</td>
  180. <td>London</td>
  181. <td>66</td>
  182. <td>$198,500</td>
  183. </tr>
  184. <tr>
  185. <td>Bradley Greer</td>
  186. <td>Software Engineer</td>
  187. <td>London</td>
  188. <td>41</td>
  189. <td>$132,000</td>
  190. </tr>
  191. <tr>
  192. <td>Angelica Ramos</td>
  193. <td>Chief Executive Officer (CEO)</td>
  194. <td>London</td>
  195. <td>47</td>
  196. <td>$1,200,000</td>
  197. </tr>
  198. <tr>
  199. <td>Suki Burks</td>
  200. <td>Developer</td>
  201. <td>London</td>
  202. <td>53</td>
  203. <td>$114,500</td>
  204. </tr>
  205. <tr>
  206. <td>Prescott Bartlett</td>
  207. <td>Technical Author</td>
  208. <td>London</td>
  209. <td>27</td>
  210. <td>$145,000</td>
  211. </tr>
  212. <tr>
  213. <td>Timothy Mooney</td>
  214. <td>Office Manager</td>
  215. <td>London</td>
  216. <td>37</td>
  217. <td>$136,200</td>
  218. </tr>
  219. <tr>
  220. <td>Bruno Nash</td>
  221. <td>Software Engineer</td>
  222. <td>London</td>
  223. <td>38</td>
  224. <td>$163,500</td>
  225. </tr>
  226. <tr>
  227. <td>Hermione Butler</td>
  228. <td>Regional Director</td>
  229. <td>London</td>
  230. <td>47</td>
  231. <td>$356,250</td>
  232. </tr>
  233. <tr>
  234. <td>Lael Greer</td>
  235. <td>Systems Administrator</td>
  236. <td>London</td>
  237. <td>21</td>
  238. <td>$103,500</td>
  239. </tr>
  240. </tbody>
  241. </table>
  242. <ul class="tabs">
  243. <li class="active">Javascript</li>
  244. <li>HTML</li>
  245. <li>CSS</li>
  246. <li>Ajax</li>
  247. <li>Server-side script</li>
  248. </ul>
  249. <div class="tabs">
  250. <div class="js">
  251. <p>The Javascript shown below is used to initialise the table shown in this
  252. example:</p><code class="multiline brush: js;">$(document).ready(function() {
  253. var tables = $('table.display').DataTable( {
  254. displayLength: 5
  255. } );
  256. // When the column visibility changes on the firs table, also change it on
  257. // the others
  258. tables.table(0).on('column-visibility', function ( e, settings, colIdx, visibility ) {
  259. tables.tables(':gt(0)').column( colIdx ).visible( visibility );
  260. } );
  261. // Create ColVis on the first table only
  262. var colvis = new $.fn.dataTable.ColVis( tables.table(0) );
  263. $( colvis.button() ).insertAfter('div.info');
  264. } );</code>
  265. <p>In addition to the above code, the following Javascript library files are loaded for use in this
  266. example:</p>
  267. <ul>
  268. <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
  269. <li><a href=
  270. "../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
  271. <li><a href="../js/dataTables.colVis.js">../js/dataTables.colVis.js</a></li>
  272. </ul>
  273. </div>
  274. <div class="table">
  275. <p>The HTML shown below is the raw HTML table element, before it has been enhanced by
  276. DataTables:</p>
  277. </div>
  278. <div class="css">
  279. <div>
  280. <p>This example uses a little bit of additional CSS beyond what is loaded from the library
  281. files (below), in order to correctly display the table. The additional CSS used is shown
  282. below:</p><code class="multiline brush: js;"></code>
  283. </div>
  284. <p>The following CSS library files are loaded for use in this example to provide the styling of the
  285. table:</p>
  286. <ul>
  287. <li><a href=
  288. "../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
  289. <li><a href="../css/dataTables.colVis.css">../css/dataTables.colVis.css</a></li>
  290. </ul>
  291. </div>
  292. <div class="ajax">
  293. <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
  294. will update automatically as any additional data is loaded.</p>
  295. </div>
  296. <div class="php">
  297. <p>The script used to perform the server-side processing for this table is shown below. Please note
  298. that this is just an example script using PHP. Server-side processing scripts can be written in any
  299. language, using <a href="//datatables.net/manual/server-side">the protocol described in the
  300. DataTables documentation</a>.</p>
  301. </div>
  302. </div>
  303. </section>
  304. </div>
  305. <section>
  306. <div class="footer">
  307. <div class="gradient"></div>
  308. <div class="liner">
  309. <h2>Other examples</h2>
  310. <div class="toc">
  311. <div class="toc-group">
  312. <h3><a href="./index.html">Examples</a></h3>
  313. <ul class="toc active">
  314. <li><a href="./simple.html">Basic initialisation</a></li>
  315. <li><a href="./new_init.html">`new` initialisation</a></li>
  316. <li><a href="./text.html">Custom button text</a></li>
  317. <li><a href="./exclude_columns.html">Exclude columns from list</a></li>
  318. <li><a href="./title_callback.html">Column button callback</a></li>
  319. <li><a href="./button_order.html">Button ordering</a></li>
  320. <li><a href="./mouseover.html">Mouseover activation</a></li>
  321. <li><a href="./group_columns.html">Group columns</a></li>
  322. <li><a href="./two_tables.html">Two tables with individual controls</a></li>
  323. <li class="active"><a href="./two_tables_identical.html">Two tables with shared
  324. controls</a></li>
  325. <li><a href="./restore.html">Restore / show all</a></li>
  326. <li><a href="./jqueryui.html">jQuery UI styling</a></li>
  327. </ul>
  328. </div>
  329. </div>
  330. <div class="epilogue">
  331. <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
  332. information about its API properties and methods.<br>
  333. Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
  334. <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
  335. DataTables.</p>
  336. <p class="copyright">DataTables designed and created by <a href=
  337. "http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2014<br>
  338. DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
  339. </div>
  340. </div>
  341. </div>
  342. </section>
  343. </body>
  344. </html>