new_init.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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>TableTools example - Initialisation with `new`</title>
  8. <link rel="stylesheet" type="text/css" href="../../../media/css/jquery.dataTables.css">
  9. <link rel="stylesheet" type="text/css" href="../css/dataTables.tableTools.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.tableTools.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 table = $('#example').DataTable();
  22. var tt = new $.fn.dataTable.TableTools( table, {
  23. sRowSelect: 'single'
  24. } );
  25. $( tt.fnContainer() ).insertAfter('div.info');
  26. } );
  27. </script>
  28. </head>
  29. <body class="dt-example">
  30. <div class="container">
  31. <section>
  32. <h1>TableTools example <span>Initialisation with `new`</span></h1>
  33. <div class="info">
  34. <p>Typically when working with TableTools, the initialisation and insertion into the DOM will be done automatically by DataTables, through the use of the <a href=
  35. "//datatables.net/reference/option/dom"><code class="option" title="DataTables initialisation option">dom<span>DT</span></code></a> parameter. However, it is also
  36. possible to initialise TableTools manually as shown in the example below using <code>new $.fn.dataTable.TableTools();</code>. The constructor for TableTools takes
  37. two parameters:</p>
  38. <ol class="markdown">
  39. <li>The DataTable that the newly created TableTools instance should attach to</li>
  40. <li>Optionally - A list of options</li>
  41. </ol>
  42. <p>Once initialised you can insert the TableTools tool bar node anywhere you wish into the DOM using the <code>fnContainer()</code> API method to get the node.</p>
  43. </div>
  44. <table id="example" class="display" cellspacing="0" width="100%">
  45. <thead>
  46. <tr>
  47. <th>Name</th>
  48. <th>Position</th>
  49. <th>Office</th>
  50. <th>Age</th>
  51. <th>Start date</th>
  52. <th>Salary</th>
  53. </tr>
  54. </thead>
  55. <tfoot>
  56. <tr>
  57. <th>Name</th>
  58. <th>Position</th>
  59. <th>Office</th>
  60. <th>Age</th>
  61. <th>Start date</th>
  62. <th>Salary</th>
  63. </tr>
  64. </tfoot>
  65. <tbody>
  66. <tr>
  67. <td>Tiger Nixon</td>
  68. <td>System Architect</td>
  69. <td>Edinburgh</td>
  70. <td>61</td>
  71. <td>2011/04/25</td>
  72. <td>$320,800</td>
  73. </tr>
  74. <tr>
  75. <td>Garrett Winters</td>
  76. <td>Accountant</td>
  77. <td>Tokyo</td>
  78. <td>63</td>
  79. <td>2011/07/25</td>
  80. <td>$170,750</td>
  81. </tr>
  82. <tr>
  83. <td>Ashton Cox</td>
  84. <td>Junior Technical Author</td>
  85. <td>San Francisco</td>
  86. <td>66</td>
  87. <td>2009/01/12</td>
  88. <td>$86,000</td>
  89. </tr>
  90. <tr>
  91. <td>Cedric Kelly</td>
  92. <td>Senior Javascript Developer</td>
  93. <td>Edinburgh</td>
  94. <td>22</td>
  95. <td>2012/03/29</td>
  96. <td>$433,060</td>
  97. </tr>
  98. <tr>
  99. <td>Airi Satou</td>
  100. <td>Accountant</td>
  101. <td>Tokyo</td>
  102. <td>33</td>
  103. <td>2008/11/28</td>
  104. <td>$162,700</td>
  105. </tr>
  106. <tr>
  107. <td>Brielle Williamson</td>
  108. <td>Integration Specialist</td>
  109. <td>New York</td>
  110. <td>61</td>
  111. <td>2012/12/02</td>
  112. <td>$372,000</td>
  113. </tr>
  114. <tr>
  115. <td>Herrod Chandler</td>
  116. <td>Sales Assistant</td>
  117. <td>San Francisco</td>
  118. <td>59</td>
  119. <td>2012/08/06</td>
  120. <td>$137,500</td>
  121. </tr>
  122. <tr>
  123. <td>Rhona Davidson</td>
  124. <td>Integration Specialist</td>
  125. <td>Tokyo</td>
  126. <td>55</td>
  127. <td>2010/10/14</td>
  128. <td>$327,900</td>
  129. </tr>
  130. <tr>
  131. <td>Colleen Hurst</td>
  132. <td>Javascript Developer</td>
  133. <td>San Francisco</td>
  134. <td>39</td>
  135. <td>2009/09/15</td>
  136. <td>$205,500</td>
  137. </tr>
  138. <tr>
  139. <td>Sonya Frost</td>
  140. <td>Software Engineer</td>
  141. <td>Edinburgh</td>
  142. <td>23</td>
  143. <td>2008/12/13</td>
  144. <td>$103,600</td>
  145. </tr>
  146. <tr>
  147. <td>Jena Gaines</td>
  148. <td>Office Manager</td>
  149. <td>London</td>
  150. <td>30</td>
  151. <td>2008/12/19</td>
  152. <td>$90,560</td>
  153. </tr>
  154. <tr>
  155. <td>Quinn Flynn</td>
  156. <td>Support Lead</td>
  157. <td>Edinburgh</td>
  158. <td>22</td>
  159. <td>2013/03/03</td>
  160. <td>$342,000</td>
  161. </tr>
  162. <tr>
  163. <td>Charde Marshall</td>
  164. <td>Regional Director</td>
  165. <td>San Francisco</td>
  166. <td>36</td>
  167. <td>2008/10/16</td>
  168. <td>$470,600</td>
  169. </tr>
  170. <tr>
  171. <td>Haley Kennedy</td>
  172. <td>Senior Marketing Designer</td>
  173. <td>London</td>
  174. <td>43</td>
  175. <td>2012/12/18</td>
  176. <td>$313,500</td>
  177. </tr>
  178. <tr>
  179. <td>Tatyana Fitzpatrick</td>
  180. <td>Regional Director</td>
  181. <td>London</td>
  182. <td>19</td>
  183. <td>2010/03/17</td>
  184. <td>$385,750</td>
  185. </tr>
  186. <tr>
  187. <td>Michael Silva</td>
  188. <td>Marketing Designer</td>
  189. <td>London</td>
  190. <td>66</td>
  191. <td>2012/11/27</td>
  192. <td>$198,500</td>
  193. </tr>
  194. <tr>
  195. <td>Paul Byrd</td>
  196. <td>Chief Financial Officer (CFO)</td>
  197. <td>New York</td>
  198. <td>64</td>
  199. <td>2010/06/09</td>
  200. <td>$725,000</td>
  201. </tr>
  202. <tr>
  203. <td>Gloria Little</td>
  204. <td>Systems Administrator</td>
  205. <td>New York</td>
  206. <td>59</td>
  207. <td>2009/04/10</td>
  208. <td>$237,500</td>
  209. </tr>
  210. <tr>
  211. <td>Bradley Greer</td>
  212. <td>Software Engineer</td>
  213. <td>London</td>
  214. <td>41</td>
  215. <td>2012/10/13</td>
  216. <td>$132,000</td>
  217. </tr>
  218. <tr>
  219. <td>Dai Rios</td>
  220. <td>Personnel Lead</td>
  221. <td>Edinburgh</td>
  222. <td>35</td>
  223. <td>2012/09/26</td>
  224. <td>$217,500</td>
  225. </tr>
  226. <tr>
  227. <td>Jenette Caldwell</td>
  228. <td>Development Lead</td>
  229. <td>New York</td>
  230. <td>30</td>
  231. <td>2011/09/03</td>
  232. <td>$345,000</td>
  233. </tr>
  234. <tr>
  235. <td>Yuri Berry</td>
  236. <td>Chief Marketing Officer (CMO)</td>
  237. <td>New York</td>
  238. <td>40</td>
  239. <td>2009/06/25</td>
  240. <td>$675,000</td>
  241. </tr>
  242. <tr>
  243. <td>Caesar Vance</td>
  244. <td>Pre-Sales Support</td>
  245. <td>New York</td>
  246. <td>21</td>
  247. <td>2011/12/12</td>
  248. <td>$106,450</td>
  249. </tr>
  250. <tr>
  251. <td>Doris Wilder</td>
  252. <td>Sales Assistant</td>
  253. <td>Sidney</td>
  254. <td>23</td>
  255. <td>2010/09/20</td>
  256. <td>$85,600</td>
  257. </tr>
  258. <tr>
  259. <td>Angelica Ramos</td>
  260. <td>Chief Executive Officer (CEO)</td>
  261. <td>London</td>
  262. <td>47</td>
  263. <td>2009/10/09</td>
  264. <td>$1,200,000</td>
  265. </tr>
  266. <tr>
  267. <td>Gavin Joyce</td>
  268. <td>Developer</td>
  269. <td>Edinburgh</td>
  270. <td>42</td>
  271. <td>2010/12/22</td>
  272. <td>$92,575</td>
  273. </tr>
  274. <tr>
  275. <td>Jennifer Chang</td>
  276. <td>Regional Director</td>
  277. <td>Singapore</td>
  278. <td>28</td>
  279. <td>2010/11/14</td>
  280. <td>$357,650</td>
  281. </tr>
  282. <tr>
  283. <td>Brenden Wagner</td>
  284. <td>Software Engineer</td>
  285. <td>San Francisco</td>
  286. <td>28</td>
  287. <td>2011/06/07</td>
  288. <td>$206,850</td>
  289. </tr>
  290. <tr>
  291. <td>Fiona Green</td>
  292. <td>Chief Operating Officer (COO)</td>
  293. <td>San Francisco</td>
  294. <td>48</td>
  295. <td>2010/03/11</td>
  296. <td>$850,000</td>
  297. </tr>
  298. <tr>
  299. <td>Shou Itou</td>
  300. <td>Regional Marketing</td>
  301. <td>Tokyo</td>
  302. <td>20</td>
  303. <td>2011/08/14</td>
  304. <td>$163,000</td>
  305. </tr>
  306. <tr>
  307. <td>Michelle House</td>
  308. <td>Integration Specialist</td>
  309. <td>Sidney</td>
  310. <td>37</td>
  311. <td>2011/06/02</td>
  312. <td>$95,400</td>
  313. </tr>
  314. <tr>
  315. <td>Suki Burks</td>
  316. <td>Developer</td>
  317. <td>London</td>
  318. <td>53</td>
  319. <td>2009/10/22</td>
  320. <td>$114,500</td>
  321. </tr>
  322. <tr>
  323. <td>Prescott Bartlett</td>
  324. <td>Technical Author</td>
  325. <td>London</td>
  326. <td>27</td>
  327. <td>2011/05/07</td>
  328. <td>$145,000</td>
  329. </tr>
  330. <tr>
  331. <td>Gavin Cortez</td>
  332. <td>Team Leader</td>
  333. <td>San Francisco</td>
  334. <td>22</td>
  335. <td>2008/10/26</td>
  336. <td>$235,500</td>
  337. </tr>
  338. <tr>
  339. <td>Martena Mccray</td>
  340. <td>Post-Sales support</td>
  341. <td>Edinburgh</td>
  342. <td>46</td>
  343. <td>2011/03/09</td>
  344. <td>$324,050</td>
  345. </tr>
  346. <tr>
  347. <td>Unity Butler</td>
  348. <td>Marketing Designer</td>
  349. <td>San Francisco</td>
  350. <td>47</td>
  351. <td>2009/12/09</td>
  352. <td>$85,675</td>
  353. </tr>
  354. <tr>
  355. <td>Howard Hatfield</td>
  356. <td>Office Manager</td>
  357. <td>San Francisco</td>
  358. <td>51</td>
  359. <td>2008/12/16</td>
  360. <td>$164,500</td>
  361. </tr>
  362. <tr>
  363. <td>Hope Fuentes</td>
  364. <td>Secretary</td>
  365. <td>San Francisco</td>
  366. <td>41</td>
  367. <td>2010/02/12</td>
  368. <td>$109,850</td>
  369. </tr>
  370. <tr>
  371. <td>Vivian Harrell</td>
  372. <td>Financial Controller</td>
  373. <td>San Francisco</td>
  374. <td>62</td>
  375. <td>2009/02/14</td>
  376. <td>$452,500</td>
  377. </tr>
  378. <tr>
  379. <td>Timothy Mooney</td>
  380. <td>Office Manager</td>
  381. <td>London</td>
  382. <td>37</td>
  383. <td>2008/12/11</td>
  384. <td>$136,200</td>
  385. </tr>
  386. <tr>
  387. <td>Jackson Bradshaw</td>
  388. <td>Director</td>
  389. <td>New York</td>
  390. <td>65</td>
  391. <td>2008/09/26</td>
  392. <td>$645,750</td>
  393. </tr>
  394. <tr>
  395. <td>Olivia Liang</td>
  396. <td>Support Engineer</td>
  397. <td>Singapore</td>
  398. <td>64</td>
  399. <td>2011/02/03</td>
  400. <td>$234,500</td>
  401. </tr>
  402. <tr>
  403. <td>Bruno Nash</td>
  404. <td>Software Engineer</td>
  405. <td>London</td>
  406. <td>38</td>
  407. <td>2011/05/03</td>
  408. <td>$163,500</td>
  409. </tr>
  410. <tr>
  411. <td>Sakura Yamamoto</td>
  412. <td>Support Engineer</td>
  413. <td>Tokyo</td>
  414. <td>37</td>
  415. <td>2009/08/19</td>
  416. <td>$139,575</td>
  417. </tr>
  418. <tr>
  419. <td>Thor Walton</td>
  420. <td>Developer</td>
  421. <td>New York</td>
  422. <td>61</td>
  423. <td>2013/08/11</td>
  424. <td>$98,540</td>
  425. </tr>
  426. <tr>
  427. <td>Finn Camacho</td>
  428. <td>Support Engineer</td>
  429. <td>San Francisco</td>
  430. <td>47</td>
  431. <td>2009/07/07</td>
  432. <td>$87,500</td>
  433. </tr>
  434. <tr>
  435. <td>Serge Baldwin</td>
  436. <td>Data Coordinator</td>
  437. <td>Singapore</td>
  438. <td>64</td>
  439. <td>2012/04/09</td>
  440. <td>$138,575</td>
  441. </tr>
  442. <tr>
  443. <td>Zenaida Frank</td>
  444. <td>Software Engineer</td>
  445. <td>New York</td>
  446. <td>63</td>
  447. <td>2010/01/04</td>
  448. <td>$125,250</td>
  449. </tr>
  450. <tr>
  451. <td>Zorita Serrano</td>
  452. <td>Software Engineer</td>
  453. <td>San Francisco</td>
  454. <td>56</td>
  455. <td>2012/06/01</td>
  456. <td>$115,000</td>
  457. </tr>
  458. <tr>
  459. <td>Jennifer Acosta</td>
  460. <td>Junior Javascript Developer</td>
  461. <td>Edinburgh</td>
  462. <td>43</td>
  463. <td>2013/02/01</td>
  464. <td>$75,650</td>
  465. </tr>
  466. <tr>
  467. <td>Cara Stevens</td>
  468. <td>Sales Assistant</td>
  469. <td>New York</td>
  470. <td>46</td>
  471. <td>2011/12/06</td>
  472. <td>$145,600</td>
  473. </tr>
  474. <tr>
  475. <td>Hermione Butler</td>
  476. <td>Regional Director</td>
  477. <td>London</td>
  478. <td>47</td>
  479. <td>2011/03/21</td>
  480. <td>$356,250</td>
  481. </tr>
  482. <tr>
  483. <td>Lael Greer</td>
  484. <td>Systems Administrator</td>
  485. <td>London</td>
  486. <td>21</td>
  487. <td>2009/02/27</td>
  488. <td>$103,500</td>
  489. </tr>
  490. <tr>
  491. <td>Jonas Alexander</td>
  492. <td>Developer</td>
  493. <td>San Francisco</td>
  494. <td>30</td>
  495. <td>2010/07/14</td>
  496. <td>$86,500</td>
  497. </tr>
  498. <tr>
  499. <td>Shad Decker</td>
  500. <td>Regional Director</td>
  501. <td>Edinburgh</td>
  502. <td>51</td>
  503. <td>2008/11/13</td>
  504. <td>$183,000</td>
  505. </tr>
  506. <tr>
  507. <td>Michael Bruce</td>
  508. <td>Javascript Developer</td>
  509. <td>Singapore</td>
  510. <td>29</td>
  511. <td>2011/06/27</td>
  512. <td>$183,000</td>
  513. </tr>
  514. <tr>
  515. <td>Donna Snider</td>
  516. <td>Customer Support</td>
  517. <td>New York</td>
  518. <td>27</td>
  519. <td>2011/01/25</td>
  520. <td>$112,000</td>
  521. </tr>
  522. </tbody>
  523. </table>
  524. <ul class="tabs">
  525. <li class="active">Javascript</li>
  526. <li>HTML</li>
  527. <li>CSS</li>
  528. <li>Ajax</li>
  529. <li>Server-side script</li>
  530. </ul>
  531. <div class="tabs">
  532. <div class="js">
  533. <p>The Javascript shown below is used to initialise the table shown in this example:</p><code class="multiline language-js">$(document).ready(function() {
  534. var table = $('#example').DataTable();
  535. var tt = new $.fn.dataTable.TableTools( table, {
  536. sRowSelect: 'single'
  537. } );
  538. $( tt.fnContainer() ).insertAfter('div.info');
  539. } );</code>
  540. <p>In addition to the above code, the following Javascript library files are loaded for use in this example:</p>
  541. <ul>
  542. <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
  543. <li><a href="../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
  544. <li><a href="../js/dataTables.tableTools.js">../js/dataTables.tableTools.js</a></li>
  545. </ul>
  546. </div>
  547. <div class="table">
  548. <p>The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:</p>
  549. </div>
  550. <div class="css">
  551. <div>
  552. <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
  553. additional CSS used is shown below:</p><code class="multiline language-css"></code>
  554. </div>
  555. <p>The following CSS library files are loaded for use in this example to provide the styling of the table:</p>
  556. <ul>
  557. <li><a href="../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
  558. <li><a href="../css/dataTables.tableTools.css">../css/dataTables.tableTools.css</a></li>
  559. </ul>
  560. </div>
  561. <div class="ajax">
  562. <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
  563. loaded.</p>
  564. </div>
  565. <div class="php">
  566. <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
  567. processing scripts can be written in any language, using <a href="//datatables.net/manual/server-side">the protocol described in the DataTables
  568. documentation</a>.</p>
  569. </div>
  570. </div>
  571. </section>
  572. </div>
  573. <section>
  574. <div class="footer">
  575. <div class="gradient"></div>
  576. <div class="liner">
  577. <h2>Other examples</h2>
  578. <div class="toc">
  579. <div class="toc-group">
  580. <h3><a href="./index.html">Examples</a></h3>
  581. <ul class="toc active">
  582. <li><a href="./simple.html">Basic initialisation</a></li>
  583. <li><a href="./swf_path.html">Setting the SWF path</a></li>
  584. <li class="active"><a href="./new_init.html">Initialisation with `new`</a></li>
  585. <li><a href="./defaults.html">Defaults</a></li>
  586. <li><a href="./select_single.html">Row selection - single row select</a></li>
  587. <li><a href="./select_multi.html">Row selection - multi-row select</a></li>
  588. <li><a href="./select_os.html">Row selection - operating system style</a></li>
  589. <li><a href="./select_column.html">Row selection - row selector on specific cells</a></li>
  590. <li><a href="./multiple_tables.html">Multiple tables</a></li>
  591. <li><a href="./multi_instance.html">Multiple toolbars</a></li>
  592. <li><a href="./collection.html">Button collections</a></li>
  593. <li><a href="./plug-in.html">Plug-in button types</a></li>
  594. <li><a href="./button_text.html">Custom button text</a></li>
  595. <li><a href="./alter_buttons.html">Button arrangement</a></li>
  596. <li><a href="./ajax.html">Ajax loaded data</a></li>
  597. <li><a href="./pdf_message.html">PDF message</a></li>
  598. <li><a href="./bootstrap.html">Bootstrap styling</a></li>
  599. <li><a href="./jqueryui.html">jQuery UI styling</a></li>
  600. </ul>
  601. </div>
  602. </div>
  603. <div class="epilogue">
  604. <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full information about its API properties and methods.<br>
  605. 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>
  606. which extend the capabilities of DataTables.</p>
  607. <p class="copyright">DataTables designed and created by <a href="http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2015<br>
  608. DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
  609. </div>
  610. </div>
  611. </div>
  612. </section>
  613. </body>
  614. </html>