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