Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 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>DataTables example - Automatic addition of row ID attributes</title> |
||
| 9 | <link rel="stylesheet" type="text/css" href="../../media/css/jquery.dataTables.css"> |
||
| 10 | <link rel="stylesheet" type="text/css" href="../resources/syntax/shCore.css"> |
||
| 11 | <link rel="stylesheet" type="text/css" href="../resources/demo.css"> |
||
| 12 | <style type="text/css" class="init"> |
||
| 13 | |||
| 14 | </style> |
||
| 15 | <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script> |
||
| 16 | <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script> |
||
| 17 | <script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js"></script> |
||
| 18 | <script type="text/javascript" language="javascript" src="../resources/demo.js"></script> |
||
| 19 | <script type="text/javascript" language="javascript" class="init"> |
||
| 20 | |||
| 21 | $(document).ready(function() { |
||
| 22 | $('#example').dataTable( { |
||
| 23 | "processing": true, |
||
| 24 | "serverSide": true, |
||
| 25 | "ajax": "scripts/ids-objects.php", |
||
| 26 | "columns": [ |
||
| 27 | { "data": "first_name" }, |
||
| 28 | { "data": "last_name" }, |
||
| 29 | { "data": "position" }, |
||
| 30 | { "data": "office" }, |
||
| 31 | { "data": "start_date" }, |
||
| 32 | { "data": "salary" } |
||
| 33 | ] |
||
| 34 | } ); |
||
| 35 | } ); |
||
| 36 | |||
| 37 | </script> |
||
| 38 | </head> |
||
| 39 | |||
| 40 | <body class="dt-example"> |
||
| 41 | <div class="container"> |
||
| 42 | <section> |
||
| 43 | <h1>DataTables example <span>Automatic addition of row ID attributes</span></h1> |
||
| 44 | |||
| 45 | <div class="info"> |
||
| 46 | <p>Often when using server-side processing you will find that it can be useful to have a specific ID on |
||
| 47 | each row (the primary key value from the database for example). By assigning the ID you want to apply |
||
| 48 | to each row using the property <code>DT_RowId</code> of the data source object for each row, DataTables |
||
| 49 | will automatically add it for you.</p> |
||
| 50 | |||
| 51 | <p>In addition to <code>DT_RowId</code> there are two other properties which perform similar actions: |
||
| 52 | <code>DT_RowClass</code> and <code>DT_RowData</code>:</p> |
||
| 53 | |||
| 54 | <ul class="markdown"> |
||
| 55 | <li>{string} <code>DT_RowId</code> - Add an ID to the <em>TR</em> element</li> |
||
| 56 | <li>{string} <code>DT_RowClass</code> - Add a class name to the <em>TR</em> element</li> |
||
| 57 | <li>{object} <code>DT_RowData</code> - Add HTML5 <em>data-</em> attributes to the <em>TR</em> |
||
| 58 | element. This is an object of key / value pairs which are assigned as data attributes to the |
||
| 59 | <em>TR</em> element.</li> |
||
| 60 | </ul> |
||
| 61 | |||
| 62 | <p>This example below shows <code>DT_RowId</code> being used to add information to the table. In |
||
| 63 | addition objects are used as the data source for the rows.</p> |
||
| 64 | </div> |
||
| 65 | |||
| 66 | <table id="example" class="display" cellspacing="0" width="100%"> |
||
| 67 | <thead> |
||
| 68 | <tr> |
||
| 69 | <th>Name</th> |
||
| 70 | <th>Position</th> |
||
| 71 | <th>Office</th> |
||
| 72 | <th>Extn.</th> |
||
| 73 | <th>Start date</th> |
||
| 74 | <th>Salary</th> |
||
| 75 | </tr> |
||
| 76 | </thead> |
||
| 77 | |||
| 78 | <tfoot> |
||
| 79 | <tr> |
||
| 80 | <th>Name</th> |
||
| 81 | <th>Position</th> |
||
| 82 | <th>Office</th> |
||
| 83 | <th>Extn.</th> |
||
| 84 | <th>Start date</th> |
||
| 85 | <th>Salary</th> |
||
| 86 | </tr> |
||
| 87 | </tfoot> |
||
| 88 | </table> |
||
| 89 | |||
| 90 | <ul class="tabs"> |
||
| 91 | <li class="active">Javascript</li> |
||
| 92 | <li>HTML</li> |
||
| 93 | <li>CSS</li> |
||
| 94 | <li>Ajax</li> |
||
| 95 | <li>Server-side script</li> |
||
| 96 | </ul> |
||
| 97 | |||
| 98 | <div class="tabs"> |
||
| 99 | <div class="js"> |
||
| 100 | <p>The Javascript shown below is used to initialise the table shown in this |
||
| 101 | example:</p><code class="multiline brush: js;">$(document).ready(function() { |
||
| 102 | $('#example').dataTable( { |
||
| 103 | "processing": true, |
||
| 104 | "serverSide": true, |
||
| 105 | "ajax": "scripts/ids-objects.php", |
||
| 106 | "columns": [ |
||
| 107 | { "data": "first_name" }, |
||
| 108 | { "data": "last_name" }, |
||
| 109 | { "data": "position" }, |
||
| 110 | { "data": "office" }, |
||
| 111 | { "data": "start_date" }, |
||
| 112 | { "data": "salary" } |
||
| 113 | ] |
||
| 114 | } ); |
||
| 115 | } );</code> |
||
| 116 | |||
| 117 | <p>In addition to the above code, the following Javascript library files are loaded for use in this |
||
| 118 | example:</p> |
||
| 119 | |||
| 120 | <ul> |
||
| 121 | <li><a href="../../media/js/jquery.js">../../media/js/jquery.js</a></li> |
||
| 122 | <li><a href="../../media/js/jquery.dataTables.js">../../media/js/jquery.dataTables.js</a></li> |
||
| 123 | </ul> |
||
| 124 | </div> |
||
| 125 | |||
| 126 | <div class="table"> |
||
| 127 | <p>The HTML shown below is the raw HTML table element, before it has been enhanced by |
||
| 128 | DataTables:</p> |
||
| 129 | </div> |
||
| 130 | |||
| 131 | <div class="css"> |
||
| 132 | <div> |
||
| 133 | <p>This example uses a little bit of additional CSS beyond what is loaded from the library |
||
| 134 | files (below), in order to correctly display the table. The additional CSS used is shown |
||
| 135 | below:</p><code class="multiline brush: js;"></code> |
||
| 136 | </div> |
||
| 137 | |||
| 138 | <p>The following CSS library files are loaded for use in this example to provide the styling of the |
||
| 139 | table:</p> |
||
| 140 | |||
| 141 | <ul> |
||
| 142 | <li><a href= |
||
| 143 | "../../media/css/jquery.dataTables.css">../../media/css/jquery.dataTables.css</a></li> |
||
| 144 | </ul> |
||
| 145 | </div> |
||
| 146 | |||
| 147 | <div class="ajax"> |
||
| 148 | <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data |
||
| 149 | will update automatically as any additional data is loaded.</p> |
||
| 150 | </div> |
||
| 151 | |||
| 152 | <div class="php"> |
||
| 153 | <p>The script used to perform the server-side processing for this table is shown below. Please note |
||
| 154 | that this is just an example script using PHP. Server-side processing scripts can be written in any |
||
| 155 | language, using <a href="//datatables.net/manual/server-side">the protocol described in the |
||
| 156 | DataTables documentation</a>.</p> |
||
| 157 | </div> |
||
| 158 | </div> |
||
| 159 | </section> |
||
| 160 | </div> |
||
| 161 | |||
| 162 | <section> |
||
| 163 | <div class="footer"> |
||
| 164 | <div class="gradient"></div> |
||
| 165 | |||
| 166 | <div class="liner"> |
||
| 167 | <h2>Other examples</h2> |
||
| 168 | |||
| 169 | <div class="toc"> |
||
| 170 | <div class="toc-group"> |
||
| 171 | <h3><a href="../basic_init/index.html">Basic initialisation</a></h3> |
||
| 172 | <ul class="toc"> |
||
| 173 | <li><a href="../basic_init/zero_configuration.html">Zero configuration</a></li> |
||
| 174 | <li><a href="../basic_init/filter_only.html">Feature enable / disable</a></li> |
||
| 175 | <li><a href="../basic_init/table_sorting.html">Default ordering (sorting)</a></li> |
||
| 176 | <li><a href="../basic_init/multi_col_sort.html">Multi-column ordering</a></li> |
||
| 177 | <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li> |
||
| 178 | <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li> |
||
| 179 | <li><a href="../basic_init/complex_header.html">Complex headers (rowspan and |
||
| 180 | colspan)</a></li> |
||
| 181 | <li><a href="../basic_init/dom.html">DOM positioning</a></li> |
||
| 182 | <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li> |
||
| 183 | <li><a href="../basic_init/state_save.html">State saving</a></li> |
||
| 184 | <li><a href="../basic_init/alt_pagination.html">Alternative pagination</a></li> |
||
| 185 | <li><a href="../basic_init/scroll_y.html">Scroll - vertical</a></li> |
||
| 186 | <li><a href="../basic_init/scroll_x.html">Scroll - horizontal</a></li> |
||
| 187 | <li><a href="../basic_init/scroll_xy.html">Scroll - horizontal and vertical</a></li> |
||
| 188 | <li><a href="../basic_init/scroll_y_theme.html">Scroll - vertical with jQuery UI |
||
| 189 | ThemeRoller</a></li> |
||
| 190 | <li><a href="../basic_init/comma-decimal.html">Language - Comma decimal place</a></li> |
||
| 191 | <li><a href="../basic_init/language.html">Language options</a></li> |
||
| 192 | </ul> |
||
| 193 | </div> |
||
| 194 | |||
| 195 | <div class="toc-group"> |
||
| 196 | <h3><a href="../advanced_init/index.html">Advanced initialisation</a></h3> |
||
| 197 | <ul class="toc"> |
||
| 198 | <li><a href="../advanced_init/events_live.html">DOM / jQuery events</a></li> |
||
| 199 | <li><a href="../advanced_init/dt_events.html">DataTables events</a></li> |
||
| 200 | <li><a href="../advanced_init/column_render.html">Column rendering</a></li> |
||
| 201 | <li><a href="../advanced_init/length_menu.html">Page length options</a></li> |
||
| 202 | <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table control |
||
| 203 | elements</a></li> |
||
| 204 | <li><a href="../advanced_init/complex_header.html">Complex headers (rowspan / |
||
| 205 | colspan)</a></li> |
||
| 206 | <li><a href="../advanced_init/html5-data-attributes.html">HTML5 data-* attributes</a></li> |
||
| 207 | <li><a href="../advanced_init/language_file.html">Language file</a></li> |
||
| 208 | <li><a href="../advanced_init/defaults.html">Setting defaults</a></li> |
||
| 209 | <li><a href="../advanced_init/row_callback.html">Row created callback</a></li> |
||
| 210 | <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li> |
||
| 211 | <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li> |
||
| 212 | <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar elements</a></li> |
||
| 213 | <li><a href="../advanced_init/sort_direction_control.html">Order direction sequence |
||
| 214 | control</a></li> |
||
| 215 | </ul> |
||
| 216 | </div> |
||
| 217 | |||
| 218 | <div class="toc-group"> |
||
| 219 | <h3><a href="../styling/index.html">Styling</a></h3> |
||
| 220 | <ul class="toc"> |
||
| 221 | <li><a href="../styling/display.html">Base style</a></li> |
||
| 222 | <li><a href="../styling/no-classes.html">Base style - no styling classes</a></li> |
||
| 223 | <li><a href="../styling/cell-border.html">Base style - cell borders</a></li> |
||
| 224 | <li><a href="../styling/compact.html">Base style - compact</a></li> |
||
| 225 | <li><a href="../styling/hover.html">Base style - hover</a></li> |
||
| 226 | <li><a href="../styling/order-column.html">Base style - order-column</a></li> |
||
| 227 | <li><a href="../styling/row-border.html">Base style - row borders</a></li> |
||
| 228 | <li><a href="../styling/stripe.html">Base style - stripe</a></li> |
||
| 229 | <li><a href="../styling/bootstrap.html">Bootstrap</a></li> |
||
| 230 | <li><a href="../styling/foundation.html">Foundation</a></li> |
||
| 231 | <li><a href="../styling/jqueryUI.html">jQuery UI ThemeRoller</a></li> |
||
| 232 | </ul> |
||
| 233 | </div> |
||
| 234 | |||
| 235 | <div class="toc-group"> |
||
| 236 | <h3><a href="../data_sources/index.html">Data sources</a></h3> |
||
| 237 | <ul class="toc"> |
||
| 238 | <li><a href="../data_sources/dom.html">HTML (DOM) sourced data</a></li> |
||
| 239 | <li><a href="../data_sources/ajax.html">Ajax sourced data</a></li> |
||
| 240 | <li><a href="../data_sources/js_array.html">Javascript sourced data</a></li> |
||
| 241 | <li><a href="../data_sources/server_side.html">Server-side processing</a></li> |
||
| 242 | </ul> |
||
| 243 | </div> |
||
| 244 | |||
| 245 | <div class="toc-group"> |
||
| 246 | <h3><a href="../api/index.html">API</a></h3> |
||
| 247 | <ul class="toc"> |
||
| 248 | <li><a href="../api/add_row.html">Add rows</a></li> |
||
| 249 | <li><a href="../api/multi_filter.html">Individual column searching (text inputs)</a></li> |
||
| 250 | <li><a href="../api/multi_filter_select.html">Individual column searching (select |
||
| 251 | inputs)</a></li> |
||
| 252 | <li><a href="../api/highlight.html">Highlighting rows and columns</a></li> |
||
| 253 | <li><a href="../api/row_details.html">Child rows (show extra / detailed |
||
| 254 | information)</a></li> |
||
| 255 | <li><a href="../api/select_row.html">Row selection (multiple rows)</a></li> |
||
| 256 | <li><a href="../api/select_single_row.html">Row selection and deletion (single |
||
| 257 | row)</a></li> |
||
| 258 | <li><a href="../api/form.html">Form inputs</a></li> |
||
| 259 | <li><a href="../api/counter_columns.html">Index column</a></li> |
||
| 260 | <li><a href="../api/show_hide.html">Show / hide columns dynamically</a></li> |
||
| 261 | <li><a href="../api/api_in_init.html">Using API in callbacks</a></li> |
||
| 262 | <li><a href="../api/tabs_and_scrolling.html">Scrolling and jQuery UI tabs</a></li> |
||
| 263 | <li><a href="../api/regex.html">Search API (regular expressions)</a></li> |
||
| 264 | </ul> |
||
| 265 | </div> |
||
| 266 | |||
| 267 | <div class="toc-group"> |
||
| 268 | <h3><a href="../ajax/index.html">Ajax</a></h3> |
||
| 269 | <ul class="toc"> |
||
| 270 | <li><a href="../ajax/simple.html">Ajax data source (arrays)</a></li> |
||
| 271 | <li><a href="../ajax/objects.html">Ajax data source (objects)</a></li> |
||
| 272 | <li><a href="../ajax/deep.html">Nested object data (objects)</a></li> |
||
| 273 | <li><a href="../ajax/objects_subarrays.html">Nested object data (arrays)</a></li> |
||
| 274 | <li><a href="../ajax/orthogonal-data.html">Orthogonal data</a></li> |
||
| 275 | <li><a href="../ajax/null_data_source.html">Generated content for a column</a></li> |
||
| 276 | <li><a href="../ajax/custom_data_property.html">Custom data source property</a></li> |
||
| 277 | <li><a href="../ajax/custom_data_flat.html">Flat array data source</a></li> |
||
| 278 | <li><a href="../ajax/defer_render.html">Deferred rendering for speed</a></li> |
||
| 279 | </ul> |
||
| 280 | </div> |
||
| 281 | |||
| 282 | <div class="toc-group"> |
||
| 283 | <h3><a href="./index.html">Server-side</a></h3> |
||
| 284 | <ul class="toc active"> |
||
| 285 | <li><a href="./simple.html">Server-side processing</a></li> |
||
| 286 | <li><a href="./custom_vars.html">Custom HTTP variables</a></li> |
||
| 287 | <li><a href="./post.html">POST data</a></li> |
||
| 288 | <li class="active"><a href="./ids.html">Automatic addition of row ID attributes</a></li> |
||
| 289 | <li><a href="./object_data.html">Object data source</a></li> |
||
| 290 | <li><a href="./row_details.html">Row details</a></li> |
||
| 291 | <li><a href="./select_rows.html">Row selection</a></li> |
||
| 292 | <li><a href="./jsonp.html">JSONP data source for remote domains</a></li> |
||
| 293 | <li><a href="./defer_loading.html">Deferred loading of data</a></li> |
||
| 294 | <li><a href="./pipeline.html">Pipelining data to reduce Ajax calls for paging</a></li> |
||
| 295 | </ul> |
||
| 296 | </div> |
||
| 297 | |||
| 298 | <div class="toc-group"> |
||
| 299 | <h3><a href="../plug-ins/index.html">Plug-ins</a></h3> |
||
| 300 | <ul class="toc"> |
||
| 301 | <li><a href="../plug-ins/api.html">API plug-in methods</a></li> |
||
| 302 | <li><a href="../plug-ins/sorting_auto.html">Ordering plug-ins (with type |
||
| 303 | detection)</a></li> |
||
| 304 | <li><a href="../plug-ins/sorting_manual.html">Ordering plug-ins (no type |
||
| 305 | detection)</a></li> |
||
| 306 | <li><a href="../plug-ins/range_filtering.html">Custom filtering - range search</a></li> |
||
| 307 | <li><a href="../plug-ins/dom_sort.html">Live DOM ordering</a></li> |
||
| 308 | </ul> |
||
| 309 | </div> |
||
| 310 | </div> |
||
| 311 | |||
| 312 | <div class="epilogue"> |
||
| 313 | <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full |
||
| 314 | information about its API properties and methods.<br> |
||
| 315 | Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and |
||
| 316 | <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of |
||
| 317 | DataTables.</p> |
||
| 318 | |||
| 319 | <p class="copyright">DataTables designed and created by <a href= |
||
| 320 | "http://www.sprymedia.co.uk">SpryMedia Ltd</a> © 2007-2014<br> |
||
| 321 | DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p> |
||
| 322 | </div> |
||
| 323 | </div> |
||
| 324 | </div> |
||
| 325 | </section> |
||
| 326 | </body> |
||
| 327 | </html> |