Classes (0) | Namespaces (0) |
Properties (0) | Static properties (14) |
Methods (0) | Static methods (0) |
Events (0) |
Properties (0) | Static properties (14) |
Methods (0) | Static methods (0) |
Events (0) |
DataTables extension options and plug-ins. This namespace acts as a collection "area" for plug-ins that can be used to extend the default DataTables behaviour - indeed many of the build in methods use this method to provide their own capabilities (sorting methods for example).
Note that this namespace is aliased to jQuery.fn.dataTableExt so it can be readily accessed and modified by plug-ins.
Plug-in filtering functions - this method of filtering is complimentary to the default type based filtering, and a lot more comprehensive as it allows you complete control over the filtering logic. Each element in this array is a function (parameters described below) that is called for every row in the table, and your logic decides if it should be included in the filtered data set or not.
Plug-in sorting functions - this method of sorting is complimentary to the default type based sorting that DataTables does automatically, allowing much greater control over the the data that is being used to sort a column. This is useful if you want to do sorting based on live data (for example the contents of an 'input' element) rather than just the static string that DataTables knows of. The way these plug-ins work is that you create an array of the values you wish to be sorted for the column in question and then return that array. Which pre-sorting function is run here depends on the sSortDataType parameter that is used for the column (if any). This is the corollary of ofnSearch for sort data.
Feature plug-ins - This is an array of objects which describe the feature plug-ins that are available to DataTables. These feature plug-ins are accessible through the sDom initialisation option. As such, each feature plug-in must describe a function that is used to initialise itself (fnInit), a character so the feature can be enabled by sDom (cFeature) and the name of the feature (sFeature). Thus the objects attached to this method must provide:
Type detection plug-in functions - DataTables utilises types to define how sorting and filtering behave, and types can be either be defined by the developer (sType for the column) or they can be automatically detected by the methods in this array. The functions defined in the array are quite simple, taking a single parameter (the data to analyse) and returning the type if it is a known type, or null otherwise.
Provide a common method for plug-ins to check the version of DataTables being used, in order to ensure compatibility.
Index for what 'this' index API functions should use
Container for all private functions in DataTables so they can be exposed externally
Pre-processing of filtering data plug-ins - When you assign the sType for a column (or have it automatically detected for you by DataTables or a type detection plug-in), you will typically be using this for custom sorting, but it can also be used to provide custom filtering by allowing you to pre-processing the data and returning the data in the format that should be filtered upon. This is done by adding functions this object with a parameter name which matches the sType for that target column. This is the corollary of afnSortData for filtering data.
Storage for the various classes that DataTables uses - jQuery UI suitable
Pagination plug-in methods - The style and controls of the pagination can significantly impact on how the end user interacts with the data in your table, and DataTables allows the addition of pagination controls by extending this object, which can then be enabled through the sPaginationType initialisation parameter. Each pagination type that is added is an object (the property name of which is what sPaginationType refers to) that has two properties, both methods that are used by DataTables to update the control's state.
Sorting plug-in methods - Sorting in DataTables is based on the detected type of the data column (you can add your own type detection functions, or override automatic detection using sType). With this specific type given to the column, DataTables will apply the required sort from the functions in the object. Each sort type must provide two mandatory methods, one each for ascending and descending sorting, and can optionally provide a pre-formatting method that will help speed up sorting by allowing DataTables to pre-format the sort data only once (rather than every time the actual sort functions are run). The two sorting functions are typical Javascript sort methods:
Storage for the various classes that DataTables uses
How should DataTables report an error. Can take the value 'alert' or 'throw'
Version string for plug-ins to check compatibility. Allowed format is a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and e are optional
Plug-in filtering functions - this method of filtering is complimentary to the default type based filtering, and a lot more comprehensive as it allows you complete control over the filtering logic. Each element in this array is a function (parameters described below) that is called for every row in the table, and your logic decides if it should be included in the filtered data set or not.
// The following example shows custom filtering being applied to the fourth column (i.e. // the aData[3] index) based on two input values from the end-user, matching the data in // a certain range. $.fn.dataTableExt.afnFiltering.push( function( oSettings, aData, iDataIndex ) { var iMin = document.getElementById('min').value * 1; var iMax = document.getElementById('max').value * 1; var iVersion = aData[3] == "-" ? 0 : aData[3]*1; if ( iMin == "" && iMax == "" ) { return true; } else if ( iMin == "" && iVersion < iMax ) { return true; } else if ( iMin < iVersion && "" == iMax ) { return true; } else if ( iMin < iVersion && iVersion < iMax ) { return true; } return false; } );
Plug-in sorting functions - this method of sorting is complimentary to the default type based sorting that DataTables does automatically, allowing much greater control over the the data that is being used to sort a column. This is useful if you want to do sorting based on live data (for example the contents of an 'input' element) rather than just the static string that DataTables knows of. The way these plug-ins work is that you create an array of the values you wish to be sorted for the column in question and then return that array. Which pre-sorting function is run here depends on the sSortDataType parameter that is used for the column (if any). This is the corollary of ofnSearch for sort data.
Note that as of v1.9, it is typically preferable to use mData to prepare data for the different uses that DataTables can put the data to. Specifically mData when used as a function will give you a 'type' (sorting, filtering etc) that you can use to prepare the data as required for the different types. As such, this method is deprecated.
// Updating the cached sorting information with user entered values in HTML input elements jQuery.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn ) { var aData = []; $( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () { aData.push( this.value ); } ); return aData; }
Feature plug-ins - This is an array of objects which describe the feature plug-ins that are available to DataTables. These feature plug-ins are accessible through the sDom initialisation option. As such, each feature plug-in must describe a function that is used to initialise itself (fnInit), a character so the feature can be enabled by sDom (cFeature) and the name of the feature (sFeature). Thus the objects attached to this method must provide:
// How TableTools initialises itself. $.fn.dataTableExt.aoFeatures.push( { "fnInit": function( oSettings ) { return new TableTools( { "oDTSettings": oSettings } ); }, "cFeature": "T", "sFeature": "TableTools" } );
Type detection plug-in functions - DataTables utilises types to define how sorting and filtering behave, and types can be either be defined by the developer (sType for the column) or they can be automatically detected by the methods in this array. The functions defined in the array are quite simple, taking a single parameter (the data to analyse) and returning the type if it is a known type, or null otherwise.
// Currency type detection plug-in: jQuery.fn.dataTableExt.aTypes.push( function ( sData ) { var sValidChars = "0123456789.-"; var Char; // Check the numeric part for ( i=1 ; i
Provide a common method for plug-ins to check the version of DataTables being used, in order to ensure compatibility.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | sVersion | string | Version string to check for, in the format "X.Y.Z". Note that the formats "X" and "X.Y" are also acceptable. |
true if this version of DataTables is greater or equal to the required version, or false if this version of DataTales is not suitable
$(document).ready(function() { var oTable = $('#example').dataTable(); alert( oTable.fnVersionCheck( '1.9.0' ) ); } );
Index for what 'this' index API functions should use
Container for all private functions in DataTables so they can be exposed externally
Pre-processing of filtering data plug-ins - When you assign the sType for a column (or have it automatically detected for you by DataTables or a type detection plug-in), you will typically be using this for custom sorting, but it can also be used to provide custom filtering by allowing you to pre-processing the data and returning the data in the format that should be filtered upon. This is done by adding functions this object with a parameter name which matches the sType for that target column. This is the corollary of afnSortData for filtering data.
Note that as of v1.9, it is typically preferable to use mData to prepare data for the different uses that DataTables can put the data to. Specifically mData when used as a function will give you a 'type' (sorting, filtering etc) that you can use to prepare the data as required for the different types. As such, this method is deprecated.
$.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) { return sData.replace(/\n/g," ").replace( /<.*?>/g, "" ); }
Storage for the various classes that DataTables uses - jQuery UI suitable
Pagination plug-in methods - The style and controls of the pagination can significantly impact on how the end user interacts with the data in your table, and DataTables allows the addition of pagination controls by extending this object, which can then be enabled through the sPaginationType initialisation parameter. Each pagination type that is added is an object (the property name of which is what sPaginationType refers to) that has two properties, both methods that are used by DataTables to update the control's state.
$.fn.dataTableExt.oPagination.four_button = { "fnInit": function ( oSettings, nPaging, fnCallbackDraw ) { nFirst = document.createElement( 'span' ); nPrevious = document.createElement( 'span' ); nNext = document.createElement( 'span' ); nLast = document.createElement( 'span' ); nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) ); nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) ); nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) ); nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) ); nFirst.className = "paginate_button first"; nPrevious.className = "paginate_button previous"; nNext.className="paginate_button next"; nLast.className = "paginate_button last"; nPaging.appendChild( nFirst ); nPaging.appendChild( nPrevious ); nPaging.appendChild( nNext ); nPaging.appendChild( nLast ); $(nFirst).click( function () { oSettings.oApi._fnPageChange( oSettings, "first" ); fnCallbackDraw( oSettings ); } ); $(nPrevious).click( function() { oSettings.oApi._fnPageChange( oSettings, "previous" ); fnCallbackDraw( oSettings ); } ); $(nNext).click( function() { oSettings.oApi._fnPageChange( oSettings, "next" ); fnCallbackDraw( oSettings ); } ); $(nLast).click( function() { oSettings.oApi._fnPageChange( oSettings, "last" ); fnCallbackDraw( oSettings ); } ); $(nFirst).bind( 'selectstart', function () { return false; } ); $(nPrevious).bind( 'selectstart', function () { return false; } ); $(nNext).bind( 'selectstart', function () { return false; } ); $(nLast).bind( 'selectstart', function () { return false; } ); }, "fnUpdate": function ( oSettings, fnCallbackDraw ) { if ( !oSettings.aanFeatures.p ) { return; } // Loop over each instance of the pager var an = oSettings.aanFeatures.p; for ( var i=0, iLen=an.length ; i
Sorting plug-in methods - Sorting in DataTables is based on the detected type of the data column (you can add your own type detection functions, or override automatic detection using sType). With this specific type given to the column, DataTables will apply the required sort from the functions in the object. Each sort type must provide two mandatory methods, one each for ascending and descending sorting, and can optionally provide a pre-formatting method that will help speed up sorting by allowing DataTables to pre-format the sort data only once (rather than every time the actual sort functions are run). The two sorting functions are typical Javascript sort methods:
// Case-sensitive string sorting, with no pre-formatting method $.extend( $.fn.dataTableExt.oSort, { "string-case-asc": function(x,y) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }, "string-case-desc": function(x,y) { return ((x < y) ? 1 : ((x > y) ? -1 : 0)); } } );
// Case-insensitive string sorting, with pre-formatting $.extend( $.fn.dataTableExt.oSort, { "string-pre": function(x) { return x.toLowerCase(); }, "string-asc": function(x,y) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }, "string-desc": function(x,y) { return ((x < y) ? 1 : ((x > y) ? -1 : 0)); } } );
Storage for the various classes that DataTables uses
How should DataTables report an error. Can take the value 'alert' or 'throw'
Version string for plug-ins to check compatibility. Allowed format is a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and e are optional