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">
8 <title>AutoFill example - Step callback</title>
9 <link rel="stylesheet" type="text/css" href="../../../media/css/jquery.dataTables.css">
10 <link rel="stylesheet" type="text/css" href="../css/dataTables.autoFill.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">
16 <script type="text/javascript" language="javascript" src="../../../media/js/jquery.js"></script>
17 <script type="text/javascript" language="javascript" src="../../../media/js/jquery.dataTables.js"></script>
18 <script type="text/javascript" language="javascript" src="../js/dataTables.autoFill.js"></script>
19 <script type="text/javascript" language="javascript" src="../../../examples/resources/syntax/shCore.js"></script>
20 <script type="text/javascript" language="javascript" src="../../../examples/resources/demo.js"></script>
21 <script type="text/javascript" language="javascript" class="init">
24 $(document).ready(function() {
25 var table = $('#example').dataTable();
27 new $.fn.dataTable.AutoFill( table, {
30 step: function ( cell, read, last, i, x, y ) {
31 var val = parseInt( (last || read).replace(/[$,]/g, ''), 10 );
32 val += (x<0 || y<0 ? -100 : 100); // - if going back up, + if going down
34 // Format for the currency column
35 return '$'+val.toString().replace( /\B(?=(\d{3})+(?!\d))/g, ',' );
45 <body class="dt-example">
46 <div class="container">
48 <h1>AutoFill example <span>Step callback</span></h1>
51 <p>By default, AutoFill will increment cells that contain numbers by a single digit for each cell that
52 is iterated over (try the <em>Age</em> column below for example). This behaviour can be disabled
53 completely using the <code>increment</code> column option, but it can also be modified to suit your
54 requirements through use of the <code>step</code> column callback function.</p>
56 <p>The <code>step</code> callback is executed for each cell in the auto-fill set and gives complete
57 control over how data is incremented. The example below shows the step function being used on the
58 <em>Salary</em> column to increment by 100, rather than 1 for each cell.</p>
60 <p>For a complete description of the <code>step</code> callback, please refer to the <a href=
61 "//datatables.net/extras/autofill/options">AutoFill documentation</a>.</p>
64 <table id="example" class="display" cellspacing="0" width="100%">
90 <td>System Architect</td>
97 <td>Garrett Winters</td>
106 <td>Junior Technical Author</td>
107 <td>San Francisco</td>
113 <td>Cedric Kelly</td>
114 <td>Senior Javascript Developer</td>
129 <td>Brielle Williamson</td>
130 <td>Integration Specialist</td>
137 <td>Herrod Chandler</td>
138 <td>Sales Assistant</td>
139 <td>San Francisco</td>
145 <td>Rhona Davidson</td>
146 <td>Integration Specialist</td>
153 <td>Colleen Hurst</td>
154 <td>Javascript Developer</td>
155 <td>San Francisco</td>
162 <td>Software Engineer</td>
170 <td>Office Manager</td>
178 <td>Support Lead</td>
185 <td>Charde Marshall</td>
186 <td>Regional Director</td>
187 <td>San Francisco</td>
193 <td>Haley Kennedy</td>
194 <td>Senior Marketing Designer</td>
201 <td>Tatyana Fitzpatrick</td>
202 <td>Regional Director</td>
209 <td>Michael Silva</td>
210 <td>Marketing Designer</td>
218 <td>Chief Financial Officer (CFO)</td>
225 <td>Gloria Little</td>
226 <td>Systems Administrator</td>
233 <td>Bradley Greer</td>
234 <td>Software Engineer</td>
242 <td>Personnel Lead</td>
249 <td>Jenette Caldwell</td>
250 <td>Development Lead</td>
258 <td>Chief Marketing Officer (CMO)</td>
265 <td>Caesar Vance</td>
266 <td>Pre-Sales Support</td>
273 <td>Doris Wilder</td>
274 <td>Sales Assistant</td>
281 <td>Angelica Ramos</td>
282 <td>Chief Executive Officer (CEO)</td>
297 <td>Jennifer Chang</td>
298 <td>Regional Director</td>
305 <td>Brenden Wagner</td>
306 <td>Software Engineer</td>
307 <td>San Francisco</td>
314 <td>Chief Operating Officer (COO)</td>
315 <td>San Francisco</td>
322 <td>Regional Marketing</td>
329 <td>Michelle House</td>
330 <td>Integration Specialist</td>
345 <td>Prescott Bartlett</td>
346 <td>Technical Author</td>
353 <td>Gavin Cortez</td>
355 <td>San Francisco</td>
361 <td>Martena Mccray</td>
362 <td>Post-Sales support</td>
369 <td>Unity Butler</td>
370 <td>Marketing Designer</td>
371 <td>San Francisco</td>
377 <td>Howard Hatfield</td>
378 <td>Office Manager</td>
379 <td>San Francisco</td>
385 <td>Hope Fuentes</td>
387 <td>San Francisco</td>
393 <td>Vivian Harrell</td>
394 <td>Financial Controller</td>
395 <td>San Francisco</td>
401 <td>Timothy Mooney</td>
402 <td>Office Manager</td>
409 <td>Jackson Bradshaw</td>
417 <td>Olivia Liang</td>
418 <td>Support Engineer</td>
426 <td>Software Engineer</td>
433 <td>Sakura Yamamoto</td>
434 <td>Support Engineer</td>
449 <td>Finn Camacho</td>
450 <td>Support Engineer</td>
451 <td>San Francisco</td>
457 <td>Serge Baldwin</td>
458 <td>Data Coordinator</td>
465 <td>Zenaida Frank</td>
466 <td>Software Engineer</td>
473 <td>Zorita Serrano</td>
474 <td>Software Engineer</td>
475 <td>San Francisco</td>
481 <td>Jennifer Acosta</td>
482 <td>Junior Javascript Developer</td>
489 <td>Cara Stevens</td>
490 <td>Sales Assistant</td>
497 <td>Hermione Butler</td>
498 <td>Regional Director</td>
506 <td>Systems Administrator</td>
513 <td>Jonas Alexander</td>
515 <td>San Francisco</td>
522 <td>Regional Director</td>
529 <td>Michael Bruce</td>
530 <td>Javascript Developer</td>
537 <td>Donna Snider</td>
538 <td>Customer Support</td>
548 <li class="active">Javascript</li>
552 <li>Server-side script</li>
557 <p>The Javascript shown below is used to initialise the table shown in this
558 example:</p><code class="multiline brush: js;">$(document).ready(function() {
559 var table = $('#example').dataTable();
561 new $.fn.dataTable.AutoFill( table, {
564 step: function ( cell, read, last, i, x, y ) {
565 var val = parseInt( (last || read).replace(/[$,]/g, ''), 10 );
566 val += (x<0 || y<0 ? -100 : 100); // - if going back up, + if going down
568 // Format for the currency column
569 return '$'+val.toString().replace( /\B(?=(\d{3})+(?!\d))/g, ',' );
575 <p>In addition to the above code, the following Javascript library files are loaded for use in this
579 <li><a href="../../../media/js/jquery.js">../../../media/js/jquery.js</a></li>
581 "../../../media/js/jquery.dataTables.js">../../../media/js/jquery.dataTables.js</a></li>
582 <li><a href="../js/dataTables.autoFill.js">../js/dataTables.autoFill.js</a></li>
587 <p>The HTML shown below is the raw HTML table element, before it has been enhanced by
593 <p>This example uses a little bit of additional CSS beyond what is loaded from the library
594 files (below), in order to correctly display the table. The additional CSS used is shown
595 below:</p><code class="multiline brush: js;"></code>
598 <p>The following CSS library files are loaded for use in this example to provide the styling of the
603 "../../../media/css/jquery.dataTables.css">../../../media/css/jquery.dataTables.css</a></li>
604 <li><a href="../css/dataTables.autoFill.css">../css/dataTables.autoFill.css</a></li>
609 <p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data
610 will update automatically as any additional data is loaded.</p>
614 <p>The script used to perform the server-side processing for this table is shown below. Please note
615 that this is just an example script using PHP. Server-side processing scripts can be written in any
616 language, using <a href="//datatables.net/manual/server-side">the protocol described in the
617 DataTables documentation</a>.</p>
625 <div class="gradient"></div>
628 <h2>Other examples</h2>
631 <div class="toc-group">
632 <h3><a href="./index.html">Examples</a></h3>
633 <ul class="toc active">
634 <li><a href="./simple.html">Basic initialisation</a></li>
635 <li><a href="./columns.html">Column options</a></li>
636 <li><a href="./scrolling.html">Scrolling DataTable</a></li>
637 <li><a href="./fill-both.html">Horizontal and vertical fill</a></li>
638 <li><a href="./fill-horizontal.html">Horizontal fill</a></li>
639 <li><a href="./complete-callback.html">Complete callback</a></li>
640 <li class="active"><a href="./step-callback.html">Step callback</a></li>
645 <div class="epilogue">
646 <p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full
647 information about its API properties and methods.<br>
648 Additionally, there are a wide range of <a href="http://www.datatables.net/extras">extras</a> and
649 <a href="http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of
652 <p class="copyright">DataTables designed and created by <a href=
653 "http://www.sprymedia.co.uk">SpryMedia Ltd</a> © 2007-2014<br>
654 DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>