AutoFill is a nice little feature on it's own, but to make it useful you will want to make use of the initialisation options, particularly callback functions, so you know when something has happened.
Initialisation of AutoFill is done by creating a new instance of the $.fn.dataTable.AutoFill
class, which takes two parameters:
AutoFill's column options can take two forms: aoColumnDefs or aColumns (or both if you prefer!) just like in DataTables. Like in DataTables aoColumnDefs must have an aTargets array to specify which columns the definition should be applied to.
bEnable or enable Why two names? Show details |
Enable AutoFill on this column or not. If disabled then the icon which provides the user interaction for the auto fill will not be shown for this column. |
Default: | true |
Type: | Boolean |
Code example: |
/* camelCase notation */ $(document).ready(function() { var table = $('#example').dataTable(); new $.fn.dataTable.AutoFill( table, { "columnDefs": [ { "enable": false, "targets": [ 0 ] } ] } ); } ); /* Using aoColumnDefs */ $(document).ready(function() { var oTable = $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumnDefs": [ { "bEnable": false, "aTargets": [ 0 ] } ] } ); } ); /* Using aoColumns */ $(document).ready(function() { $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumns": [ { "bEnable": false }, null, null, null, null ] } ); } ); |
fnRead or read Why two names? Show details |
Function used to read a value from a given TD cell. This can be used to manipulate input elements, for example, or any given markup rather than using the default AutoFill reading. |
Default: | null |
Input parameters: |
|
Return parameter: | String - read information |
Code example: |
/* Using camelCase notation */ $(document).ready(function() { var table = $('#example').dataTable(); new $.fn.dataTable.AutoFill( table, { "columnDefs": [ { "read": function ( cell ) { return $('span', cell).attr('title'); }, "targets": [ 0 ] } ] } ); } ); /* Using aoColumnDefs */ $(document).ready(function() { var oTable = $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumnDefs": [ { "fnRead": function ( nTd ) { return $('span', nTd).attr('title'); }, "aTargets": [ 0 ] } ] } ); } ); /* Using aoColumns */ $(document).ready(function() { $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumns": [ { "fnRead": function ( nTd ) { return $('span', nTd).attr('title'); } }, null, null, null, null ] } ); } ); |
fnStep or step Why two names? Show details |
This callback provides the ability to customise the incrementing of data during the auto fill. It's relation to fnRead and fnWrite is that this function is called in-between the two (i.e. the sequence is read, calculate, write - loop). The code example shows a non-incrementing implementation (i.e. for integers when autofilling the string will not be changed). |
Default: | null |
Input parameters: |
|
Return parameter: | string - calculated value |
Code example: |
/* camelCase notation */ $(document).ready(function() { var table = $('#example').dataTable(); new $.fn.dataTable.AutoFill( table, { "columnDefs": [ { "step": function ( cell, read, last, i, x, y ) { // simple increment by 10 return last === undefined ? read : last+10; }, "targets": [ 0 ] } ] } ); } ); /* Using aoColumnDefs */ $(document).ready(function() { var oTable = $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumnDefs": [ { "fnStep": function ( cell, read, last, i, x, y ) { // simple increment by 10 return last === undefined ? read : last+10; }, "aTargets": [ 0 ] } ] } ); } ); /* Using aoColumns */ $(document).ready(function() { $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumns": [ { "fnStep": function ( cell, read, last, i, x, y ) { // simple increment by 10 return last === undefined ? read : last+10; } }, null, null, null, null ] } ); } ); |
fnWrite or write Why two names? Show details |
This callback is the corollary of fnRead, providing a method to customise how AutoFill writes a calculated fill value to a given cell. By default AutoFill will set the value in an input or select element in a cell if found, otherwise it will set the value as HTML. |
Default: | null |
Input parameters: |
|
Return parameter: | void |
Code example: |
/* camelCase notation */ $(document).ready(function() { var table = $('#example').dataTable(); new $.fn.dataTable.AutoFill( table, { "aoColumnDefs": [ { "write": function ( cell, val ) { return $('span', cell).attr('title', val ); }, "targets": [ 0 ] } ] } ); } ); /* Using aoColumnDefs */ $(document).ready(function() { var oTable = $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumnDefs": [ { "fnWrite": function ( nTd, sValue ) { return $('span', nTd).attr('title', sValue ); }, "aTargets": [ 0 ] } ] } ); } ); /* Using aoColumns */ $(document).ready(function() { $('#example').dataTable(); new $.fn.dataTable.AutoFill( oTable, { "aoColumns": [ { "fnWrite": function ( nTd, sValue ) { return $('span', nTd).attr('title', sValue ); } }, null, null, null, null ] } ); } ); |