1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" />
7 <title>DataTables example</title>
8 <style type="text/css" title="currentStyle">
9 @import "../../media/css/demo_page.css";
10 @import "../../media/css/demo_table.css";
12 <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
13 <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
14 <script type="text/javascript" charset="utf-8">
15 $(document).ready(function() {
16 $('#example').dataTable( {
17 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
19 * Calculate the total market share for all browsers in this table (ie inc. outside
23 for ( var i=0 ; i<aaData.length ; i++ )
25 iTotalMarket += aaData[i][4]*1;
28 /* Calculate the market share for browsers on this page */
30 for ( var i=iStart ; i<iEnd ; i++ )
32 iPageMarket += aaData[ aiDisplay[i] ][4]*1;
35 /* Modify the footer row to match what we want */
36 var nCells = nRow.getElementsByTagName('th');
37 nCells[1].innerHTML = parseInt(iPageMarket * 100)/100 +
38 '% ('+ parseInt(iTotalMarket * 100)/100 +'% total)';
44 <body id="dt_example">
46 <div class="full_width big">
47 DataTables footer callback example
51 <p>DataTables using the header and footer callback manipulation functions (fnHeaderCallback() and fnFooterCallback()) you can perform some powerful and useful data manipulation. The example given below shows how a callback function can be used to total up visible (and hidden) data, taking into account all of DataTable's features (pagination, filtering etc).</p>
55 <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
58 <th>Rendering engine</th>
60 <th>Engine version</th>
62 <th style="width: 150px">Market share (%)</th>
73 <td class="center">4</td>
74 <td class="center">X</td>
75 <td class="center">0.01</td>
81 <td class="center">5</td>
82 <td class="center">C</td>
83 <td class="center">0.1</td>
89 <td class="center">5.5</td>
90 <td class="center">A</td>
91 <td class="center">0.5</td>
97 <td class="center">6</td>
98 <td class="center">A</td>
99 <td class="center">36</td>
103 <td>Internet Explorer 7</td>
104 <td class="center">7</td>
105 <td class="center">A</td>
106 <td class="center">41</td>
110 <td>AOL browser (AOL desktop)</td>
111 <td class="center">6</td>
112 <td class="center">A</td>
113 <td class="center">1</td>
118 <td class="center">1.7</td>
119 <td class="center">A</td>
120 <td class="center">0.1</td>
125 <td class="center">1.8</td>
126 <td class="center">A</td>
127 <td class="center">0.5</td>
132 <td class="center">1.8</td>
133 <td class="center">A</td>
134 <td class="center">7</td>
139 <td class="center">1.9</td>
140 <td class="center">A</td>
141 <td class="center">9</td>
146 <td class="center">1.8</td>
147 <td class="center">A</td>
148 <td class="center">0.01</td>
153 <td class="center">1.8</td>
154 <td class="center">A</td>
155 <td class="center">0.01</td>
159 <td>Netscape 7.2</td>
160 <td class="center">1.7</td>
161 <td class="center">A</td>
162 <td class="center">0.01</td>
166 <td>Netscape Browser 8</td>
167 <td class="center">1.7</td>
168 <td class="center">A</td>
169 <td class="center">0.01</td>
173 <td>Netscape Navigator 9</td>
174 <td class="center">1.8</td>
175 <td class="center">A</td>
176 <td class="center">0.01</td>
181 <td class="center">1</td>
182 <td class="center">A</td>
183 <td class="center">0.01</td>
188 <td class="center">1.1</td>
189 <td class="center">A</td>
190 <td class="center">0.01</td>
195 <td class="center">1.2</td>
196 <td class="center">A</td>
197 <td class="center">0.01</td>
202 <td class="center">1.3</td>
203 <td class="center">A</td>
204 <td class="center">0.01</td>
209 <td class="center">1.4</td>
210 <td class="center">A</td>
211 <td class="center">0.01</td>
216 <td class="center">1.5</td>
217 <td class="center">A</td>
218 <td class="center">0.01</td>
223 <td class="center">1.6</td>
224 <td class="center">A</td>
225 <td class="center">0.01</td>
230 <td class="center">1.7</td>
231 <td class="center">A</td>
232 <td class="center">0.01</td>
237 <td class="center">1.8</td>
238 <td class="center">A</td>
239 <td class="center">0.01</td>
243 <td>Seamonkey 1.1</td>
244 <td class="center">1.8</td>
245 <td class="center">A</td>
246 <td class="center">0.01</td>
250 <td>Epiphany 2.20</td>
251 <td class="center">1.8</td>
252 <td class="center">A</td>
253 <td class="center">0.01</td>
258 <td class="center">125.5</td>
259 <td class="center">A</td>
260 <td class="center">0.01</td>
265 <td class="center">312.8</td>
266 <td class="center">A</td>
267 <td class="center">0.01</td>
272 <td class="center">419.3</td>
273 <td class="center">A</td>
274 <td class="center">1</td>
279 <td class="center">522.1</td>
280 <td class="center">A</td>
281 <td class="center">2.2</td>
286 <td class="center">420</td>
287 <td class="center">A</td>
288 <td class="center">0.01</td>
292 <td>iPod Touch / iPhone</td>
293 <td class="center">420.1</td>
294 <td class="center">A</td>
295 <td class="center">0.05</td>
300 <td class="center">413</td>
301 <td class="center">A</td>
302 <td class="center">0.01</td>
307 <td class="center">-</td>
308 <td class="center">A</td>
309 <td class="center">0.01</td>
314 <td class="center">-</td>
315 <td class="center">A</td>
316 <td class="center">0.01</td>
321 <td class="center">-</td>
322 <td class="center">A</td>
323 <td class="center">0.01</td>
328 <td class="center">-</td>
329 <td class="center">A</td>
330 <td class="center">0.01</td>
335 <td class="center">-</td>
336 <td class="center">A</td>
337 <td class="center">0.1</td>
342 <td class="center">-</td>
343 <td class="center">A</td>
344 <td class="center">0.2</td>
349 <td class="center">-</td>
350 <td class="center">A</td>
351 <td class="center">0.8</td>
355 <td>Opera for Wii</td>
356 <td class="center">-</td>
357 <td class="center">A</td>
358 <td class="center">0.01</td>
363 <td class="center">-</td>
364 <td class="center">A</td>
365 <td class="center">0.01</td>
369 <td>Nintendo DS browser</td>
370 <td class="center">8.5</td>
371 <td class="center">C/A<sup>1</sup></td>
372 <td class="center">0.01</td>
376 <td>Konqureror 3.1</td>
377 <td class="center">3.1</td>
378 <td class="center">C</td>
379 <td class="center">0.01</td>
383 <td>Konqureror 3.3</td>
384 <td class="center">3.3</td>
385 <td class="center">A</td>
386 <td class="center">0.01</td>
390 <td>Konqureror 3.5</td>
391 <td class="center">3.5</td>
392 <td class="center">A</td>
393 <td class="center">0.01</td>
397 <td>Internet Explorer 4.5</td>
398 <td class="center">-</td>
399 <td class="center">X</td>
400 <td class="center">0.01</td>
404 <td>Internet Explorer 5.1</td>
405 <td class="center">1</td>
406 <td class="center">C</td>
407 <td class="center">0.01</td>
411 <td>Internet Explorer 5.2</td>
412 <td class="center">1</td>
413 <td class="center">C</td>
414 <td class="center">0.01</td>
418 <td>NetFront 3.1</td>
419 <td class="center">-</td>
420 <td class="center">C</td>
421 <td class="center">0.01</td>
425 <td>NetFront 3.4</td>
426 <td class="center">-</td>
427 <td class="center">A</td>
428 <td class="center">0.01</td>
433 <td class="center">-</td>
434 <td class="center">X</td>
435 <td class="center">0.01</td>
440 <td class="center">-</td>
441 <td class="center">X</td>
442 <td class="center">0.01</td>
447 <td class="center">-</td>
448 <td class="center">X</td>
449 <td class="center">0.01</td>
454 <td class="center">-</td>
455 <td class="center">C</td>
456 <td class="center">0.01</td>
461 <td class="center">-</td>
462 <td class="center">C</td>
463 <td class="center">0.01</td>
466 <td>Other browsers</td>
468 <td class="center">-</td>
469 <td class="center">U</td>
470 <td class="center">0.04</td>
475 <th style="text-align:right" colspan="4">Total:</th>
481 <div class="spacer"></div>
483 <p class="space">Warning! The market share information given in this table is <b>fabricated</b> using a combination of (mild) judgement, the <a href="http://www.mail-archive.com/backstage@lists.bbc.co.uk/msg03899.html">BBC Browser Statistics</a> information and statistics from <a href="http://www.thecounter.com/stats/2008/August/browser.php">TheCounter.com</a>. THe lowest usage given to anyone browser is 0.01 for reasons of this example.</p>
486 <h1>Initialisation code</h1>
487 <pre class="brush: js;">$(document).ready(function() {
488 $('#example').dataTable( {
489 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
491 * Calculate the total market share for all browsers in this table (ie inc. outside
494 var iTotalMarket = 0;
495 for ( var i=0 ; i<aaData.length ; i++ )
497 iTotalMarket += aaData[i][4]*1;
500 /* Calculate the market share for browsers on this page */
502 for ( var i=iStart ; i<iEnd ; i++ )
504 iPageMarket += aaData[ aiDisplay[i] ][4]*1;
507 /* Modify the footer row to match what we want */
508 var nCells = nRow.getElementsByTagName('th');
509 nCells[1].innerHTML = parseInt(iPageMarket * 100)/100 +
510 '% ('+ parseInt(iTotalMarket * 100)/100 +'% total)';
514 <style type="text/css">
515 @import "../examples_support/syntax/css/shCore.css";
517 <script type="text/javascript" language="javascript" src="../examples_support/syntax/js/shCore.js"></script>
520 <h1>Other examples</h1>
521 <div class="demo_links">
522 <h2>Basic initialisation</h2>
524 <li><a href="../basic_init/zero_config.html">Zero configuration</a></li>
525 <li><a href="../basic_init/filter_only.html">Feature enablement</a></li>
526 <li><a href="../basic_init/table_sorting.html">Sorting data</a></li>
527 <li><a href="../basic_init/multi_col_sort.html">Multi-column sorting</a></li>
528 <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
529 <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
530 <li><a href="../basic_init/complex_header.html">Complex headers - grouping with colspan</a></li>
531 <li><a href="../basic_init/dom.html">DOM positioning</a></li>
532 <li><a href="../basic_init/flexible_width.html">Flexible table width</a></li>
533 <li><a href="../basic_init/state_save.html">State saving</a></li>
534 <li><a href="../basic_init/alt_pagination.html">Alternative pagination styles</a></li>
536 <a href="../basic_init/scroll_x.html">Horizontal</a> /
537 <a href="../basic_init/scroll_y.html">Vertical</a> /
538 <a href="../basic_init/scroll_xy.html">Both</a> /
539 <a href="../basic_init/scroll_y_theme.html">Themed</a> /
540 <a href="../basic_init/scroll_y_infinite.html">Infinite</a>
542 <li><a href="../basic_init/language.html">Change language information (internationalisation)</a></li>
543 <li><a href="../basic_init/themes.html">ThemeRoller themes (Smoothness)</a></li>
546 <h2>Advanced initialisation</h2>
549 <a href="../advanced_init/events_live.html">Live events</a> /
550 <a href="../advanced_init/events_pre_init.html">Pre-init</a> /
551 <a href="../advanced_init/events_post_init.html">Post-init</a>
553 <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
554 <li><a href="../advanced_init/html_sort.html">Sorting without HTML tags</a></li>
555 <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table controls (sDom)</a></li>
556 <li><a href="../advanced_init/length_menu.html">Defining length menu options</a></li>
557 <li><a href="../advanced_init/complex_header.html">Complex headers and hidden columns</a></li>
558 <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar (element) around table</a></li>
559 <li><a href="../advanced_init/highlight.html">Row highlighting with CSS</a></li>
560 <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
561 <li><a href="../advanced_init/row_callback.html">Row callback</a></li>
562 <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
563 <li><a href="../advanced_init/sorting_control.html">Control sorting direction of columns</a></li>
564 <li><a href="../advanced_init/language_file.html">Change language information from a file (internationalisation)</a></li>
565 <li><a href="../advanced_init/defaults.html">Setting defaults</a></li>
566 <li><a href="../advanced_init/localstorage.html">State saving with localStorage</a></li>
567 <li><a href="../advanced_init/dt_events.html">Custom events</a></li>
572 <li><a href="../api/add_row.html">Dynamically add a new row</a></li>
573 <li><a href="../api/multi_filter.html">Individual column filtering (using "input" elements)</a></li>
574 <li><a href="../api/multi_filter_select.html">Individual column filtering (using "select" elements)</a></li>
575 <li><a href="../api/highlight.html">Highlight rows and columns</a></li>
576 <li><a href="../api/row_details.html">Show and hide details about a particular record</a></li>
577 <li><a href="../api/select_row.html">User selectable rows (multiple rows)</a></li>
578 <li><a href="../api/select_single_row.html">User selectable rows (single row) and delete rows</a></li>
579 <li><a href="../api/editable.html">Editable rows (with jEditable)</a></li>
580 <li><a href="../api/form.html">Submit form with elements in table</a></li>
581 <li><a href="../api/counter_column.html">Index column (static number column)</a></li>
582 <li><a href="../api/show_hide.html">Show and hide columns dynamically</a></li>
583 <li><a href="../api/api_in_init.html">API function use in initialisation object (callback)</a></li>
584 <li><a href="../api/tabs_and_scrolling.html">DataTables scrolling and tabs</a></li>
585 <li><a href="../api/regex.html">Regular expression filtering</a></li>
589 <div class="demo_links">
590 <h2>Data sources</h2>
592 <li><a href="../data_sources/dom.html">DOM</a></li>
593 <li><a href="../data_sources/js_array.html">Javascript array</a></li>
594 <li><a href="../data_sources/ajax.html">Ajax source</a></li>
595 <li><a href="../data_sources/server_side.html">Server side processing</a></li>
598 <h2>Server-side processing</h2>
600 <li><a href="../server_side/server_side.html">Obtain server-side data</a></li>
601 <li><a href="../server_side/custom_vars.html">Add extra HTTP variables</a></li>
602 <li><a href="../server_side/post.html">Use HTTP POST</a></li>
603 <li><a href="../server_side/ids.html">Automatic addition of IDs and classes to rows</a></li>
604 <li><a href="../server_side/object_data.html">Reading table data from objects</a></li>
605 <li><a href="../server_side/row_details.html">Show and hide details about a particular record</a></li>
606 <li><a href="../server_side/select_rows.html">User selectable rows (multiple rows)</a></li>
607 <li><a href="../server_side/jsonp.html">JSONP for a cross domain data source</a></li>
608 <li><a href="../server_side/editable.html">jEditable integration with DataTables</a></li>
609 <li><a href="../server_side/defer_loading.html">Deferred loading of Ajax data</a></li>
610 <li><a href="../server_side/pipeline.html">Pipelining data (reduce Ajax calls for paging)</a></li>
613 <h2>Ajax data source</h2>
615 <li><a href="../ajax/ajax.html">Ajax sourced data (array of arrays)</a></li>
616 <li><a href="../ajax/objects.html">Ajax sourced data (array of objects)</a></li>
617 <li><a href="../ajax/defer_render.html">Deferred DOM creation for extra speed</a></li>
618 <li><a href="../ajax/null_data_source.html">Empty data source columns</a></li>
619 <li><a href="../ajax/custom_data_property.html">Use a data source other than aaData (the default)</a></li>
620 <li><a href="../ajax/objects_subarrays.html">Read column data from sub-arrays</a></li>
621 <li><a href="../ajax/deep.html">Read column data from deeply nested properties</a></li>
626 <li><a href="../plug-ins/plugin_api.html">Add custom API functions</a></li>
627 <li><a href="../plug-ins/sorting_plugin.html">Sorting and automatic type detection</a></li>
628 <li><a href="../plug-ins/sorting_sType.html">Sorting without automatic type detection</a></li>
629 <li><a href="../plug-ins/paging_plugin.html">Custom pagination controls</a></li>
630 <li><a href="../plug-ins/range_filtering.html">Range filtering / custom filtering</a></li>
631 <li><a href="../plug-ins/dom_sort.html">Live DOM sorting</a></li>
632 <li><a href="../plug-ins/html_sort.html">Automatic HTML type detection</a></li>
637 <div id="footer" class="clear" style="text-align:center;">
639 Please refer to the <a href="http://www.datatables.net/usage">DataTables documentation</a> for full information about its API properties and methods.<br>
640 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> which extend the capabilities of DataTables.
643 <span style="font-size:10px;">
644 DataTables designed and created by <a href="http://www.sprymedia.co.uk">Allan Jardine</a> © 2007-2011<br>
645 DataTables is dual licensed under the <a href="http://www.datatables.net/license_gpl2">GPL v2 license</a> or a <a href="http://www.datatables.net/license_bsd">BSD (3-point) license</a>.