select_column.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 - Row selection - row selector on specific cells</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="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.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. tr td:first-child {
  15. text-align: center;
  16. }
  17. tr td:first-child:before {
  18. content: "\f096"; /* fa-square-o */
  19. font-family: FontAwesome;
  20. }
  21. tr.selected td:first-child:before {
  22. content: "\f046"; /* fa-check-square-o */
  23. }
  24. </style>
  25. <script type="text/javascript" language="javascript" src="../../../media/js/jquery.js"></script>
  26. <script type="text/javascript" language="javascript" src="../../../media/js/jquery.dataTables.js"></script>
  27. <script type="text/javascript" language="javascript" src="../js/dataTables.tableTools.js"></script>
  28. <script type="text/javascript" language="javascript" src="../../../examples/resources/syntax/shCore.js"></script>
  29. <script type="text/javascript" language="javascript" src="../../../examples/resources/demo.js"></script>
  30. <script type="text/javascript" language="javascript" class="init">
  31. $(document).ready(function() {
  32. $('#example').DataTable( {
  33. ajax: "../../../examples/ajax/data/objects.txt",
  34. columns: [
  35. { data: null, defaultContent: '', orderable: false },
  36. { data: 'name' },
  37. { data: 'position' },
  38. { data: 'office' },
  39. { data: 'extn' },
  40. { data: 'start_date' },
  41. { data: 'salary' }
  42. ],
  43. order: [ 1, 'asc' ],
  44. dom: 'T<"clear">lfrtip',
  45. tableTools: {
  46. sRowSelect: 'os',
  47. sRowSelector: 'td:first-child',
  48. aButtons: [ 'select_all', 'select_none' ]
  49. }
  50. } );
  51. } );
  52. </script>
  53. </head>
  54. <body class="dt-example">
  55. <div class="container">
  56. <section>
  57. <h1>TableTools example <span>Row selection - row selector on specific cells</span></h1>
  58. <div class="info">
  59. <p>By default, TableTools' row selector option will register a row selection click on any part of the row. Although this is often desirable, you might wish at
  60. times to limit the row selection to just a single column, or other elements in the row. This might be useful, for example, with <a href=
  61. "//editor.datatables.net">Editor's</a> inline editing, so you don't select the row on click of a cell that is to be edited.</p>
  62. <p>The <code>sRowSelector</code> method provides this ability, allowing a custom jQuery selector to be passed in. TableTools will use the parent row of any element
  63. that is selected by the end user.</p>
  64. <p>In this case, the row selector is attached to the cells in the first column of the table, and <a href="http://fortawesome.github.io/Font-Awesome">Font
  65. Awesome</a> is used to display a checkbox indicating the selection state of the row, in addition to the row background colouring.</p>
  66. </div>
  67. <table id="example" class="display" cellspacing="0" width="100%">
  68. <thead>
  69. <tr>
  70. <th>
  71. <th>Name</th>
  72. <th>Position</th>
  73. <th>Office</th>
  74. <th>Age</th>
  75. <th>Start date</th>
  76. <th>Salary</th>
  77. </tr>
  78. </thead>
  79. </table>
  80. <ul class="tabs">
  81. <li class="active">Javascript</li>
  82. <li>HTML</li>
  83. <li>CSS</li>
  84. <li>Ajax</li>
  85. <li>Server-side script</li>
  86. </ul>
  87. <div class="tabs">
  88. <div class="js">
  89. <p>The Javascript shown below is used to initialise the table shown in this example:</p><code class="multiline language-js">$(document).ready(function() {
  90. $('#example').DataTable( {
  91. ajax: &quot;../../../examples/ajax/data/objects.txt&quot;,
  92. columns: [
  93. { data: null, defaultContent: '', orderable: false },
  94. { data: 'name' },
  95. { data: 'position' },
  96. { data: 'office' },
  97. { data: 'extn' },
  98. { data: 'start_date' },
  99. { data: 'salary' }
  100. ],
  101. order: [ 1, 'asc' ],
  102. dom: 'T&lt;&quot;clear&quot;&gt;lfrtip',
  103. tableTools: {
  104. sRowSelect: 'os',
  105. sRowSelector: 'td:first-child',
  106. aButtons: [ 'select_all', 'select_none' ]
  107. }
  108. } );
  109. } );</code>
  110. <p>In addition to the above code, the following Javascript library files are loaded for use in this example:</p>
  111. <ul>
  112. <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
  113. <li><a href="../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
  114. <li><a href="../js/dataTables.tableTools.js">../js/dataTables.tableTools.js</a></li>
  115. </ul>
  116. </div>
  117. <div class="table">
  118. <p>The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:</p>
  119. </div>
  120. <div class="css">
  121. <div>
  122. <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
  123. additional CSS used is shown below:</p><code class="multiline language-css">tr td:first-child {
  124. text-align: center;
  125. }
  126. tr td:first-child:before {
  127. content: &quot;\f096&quot;; /* fa-square-o */
  128. font-family: FontAwesome;
  129. }
  130. tr.selected td:first-child:before {
  131. content: &quot;\f046&quot;; /* fa-check-square-o */
  132. }</code>
  133. </div>
  134. <p>The following CSS library files are loaded for use in this example to provide the styling of the table:</p>
  135. <ul>
  136. <li><a href="../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
  137. <li><a href="../css/dataTables.tableTools.css">../css/dataTables.tableTools.css</a></li>
  138. <li><a href=
  139. "//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css">//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css</a></li>
  140. </ul>
  141. </div>
  142. <div class="ajax">
  143. <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
  144. loaded.</p>
  145. </div>
  146. <div class="php">
  147. <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
  148. processing scripts can be written in any language, using <a href="//datatables.net/manual/server-side">the protocol described in the DataTables
  149. documentation</a>.</p>
  150. </div>
  151. </div>
  152. </section>
  153. </div>
  154. <section>
  155. <div class="footer">
  156. <div class="gradient"></div>
  157. <div class="liner">
  158. <h2>Other examples</h2>
  159. <div class="toc">
  160. <div class="toc-group">
  161. <h3><a href="./index.html">Examples</a></h3>
  162. <ul class="toc active">
  163. <li><a href="./simple.html">Basic initialisation</a></li>
  164. <li><a href="./swf_path.html">Setting the SWF path</a></li>
  165. <li><a href="./new_init.html">Initialisation with `new`</a></li>
  166. <li><a href="./defaults.html">Defaults</a></li>
  167. <li><a href="./select_single.html">Row selection - single row select</a></li>
  168. <li><a href="./select_multi.html">Row selection - multi-row select</a></li>
  169. <li><a href="./select_os.html">Row selection - operating system style</a></li>
  170. <li class="active"><a href="./select_column.html">Row selection - row selector on specific cells</a></li>
  171. <li><a href="./multiple_tables.html">Multiple tables</a></li>
  172. <li><a href="./multi_instance.html">Multiple toolbars</a></li>
  173. <li><a href="./collection.html">Button collections</a></li>
  174. <li><a href="./plug-in.html">Plug-in button types</a></li>
  175. <li><a href="./button_text.html">Custom button text</a></li>
  176. <li><a href="./alter_buttons.html">Button arrangement</a></li>
  177. <li><a href="./ajax.html">Ajax loaded data</a></li>
  178. <li><a href="./pdf_message.html">PDF message</a></li>
  179. <li><a href="./bootstrap.html">Bootstrap styling</a></li>
  180. <li><a href="./jqueryui.html">jQuery UI styling</a></li>
  181. </ul>
  182. </div>
  183. </div>
  184. <div class="epilogue">
  185. <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full information about its API properties and methods.<br>
  186. 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>
  187. which extend the capabilities of DataTables.</p>
  188. <p class="copyright">DataTables designed and created by <a href="http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2015<br>
  189. DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
  190. </div>
  191. </div>
  192. </div>
  193. </section>
  194. </body>
  195. </html>