1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-02 14:24:11 +01:00

ize - refactor _fnInitialise for size. Only about 60 bytes saved

This commit is contained in:
Allan Jardine 2013-10-11 14:21:49 +01:00
parent 5c0cdd86cd
commit c3a2ad6f40
2 changed files with 48 additions and 52 deletions

View File

@ -1 +1 @@
a0417585115ca4bb8a6675eed7738724432ad032 3818add76a9bf921d51be2488f47e190677f4883

View File

@ -2609,82 +2609,78 @@
/** /**
* Draw the table for the first time, adding all required features * Draw the table for the first time, adding all required features
* @param {object} oSettings dataTables settings object * @param {object} settings dataTables settings object
* @memberof DataTable#oApi * @memberof DataTable#oApi
*/ */
function _fnInitialise ( oSettings ) function _fnInitialise ( settings )
{ {
var i, iLen, iAjaxStart=oSettings.iInitDisplayStart; var i, iLen, iAjaxStart=settings.iInitDisplayStart;
var columns = settings.aoColumn, column;
var features = settings.oFeatures;
/* Ensure that the table data is fully initialised */ /* Ensure that the table data is fully initialised */
if ( oSettings.bInitialised === false ) if ( ! settings.bInitialised ) {
{ setTimeout( function(){ _fnInitialise( settings ); }, 200 );
setTimeout( function(){ _fnInitialise( oSettings ); }, 200 );
return; return;
} }
/* Show the display HTML options */ /* Show the display HTML options */
_fnAddOptionsHtml( oSettings ); _fnAddOptionsHtml( settings );
/* Build and draw the header / footer for the table */ /* Build and draw the header / footer for the table */
_fnBuildHead( oSettings ); _fnBuildHead( settings );
_fnDrawHead( oSettings, oSettings.aoHeader ); _fnDrawHead( settings, settings.aoHeader );
_fnDrawHead( oSettings, oSettings.aoFooter ); _fnDrawHead( settings, settings.aoFooter );
/* Okay to show that something is going on now */ /* Okay to show that something is going on now */
_fnProcessingDisplay( oSettings, true ); _fnProcessingDisplay( settings, true );
/* Calculate sizes for columns */ /* Calculate sizes for columns */
if ( oSettings.oFeatures.bAutoWidth ) if ( features.bAutoWidth ) {
{ _fnCalculateColumnWidths( settings );
_fnCalculateColumnWidths( oSettings );
} }
for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ ) for ( i=0, iLen=columns.length ; i<iLen ; i++ ) {
{ column = columns[i];
if ( oSettings.aoColumns[i].sWidth !== null )
{ if ( column.sWidth ) {
oSettings.aoColumns[i].nTh.style.width = _fnStringToCss( oSettings.aoColumns[i].sWidth ); column.nTh.style.width = _fnStringToCss( column.sWidth );
} }
} }
/* If there is default sorting required - let's do it. The sort function will do the // If there is default sorting required - let's do it. The sort function
* drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows // will do the drawing for us. Otherwise we draw the table regardless of the
* the table to look initialised for Ajax sourcing data (show 'loading' message possibly) // Ajax source - this allows the table to look initialised for Ajax sourcing
*/ // data (show 'loading' message possibly)
_fnReDraw( oSettings ); _fnReDraw( settings );
/* if there is an ajax source load the data */ // Server-side processing init complete is done by _fnAjaxUpdateDraw
if ( (oSettings.sAjaxSource || oSettings.ajax) && !oSettings.oFeatures.bServerSide ) if ( ! features.bServerSide ) {
{ // if there is an ajax source load the data
var aoData = []; if ( settings.sAjaxSource || settings.ajax ) {
_fnBuildAjax( oSettings, [], function(json) { _fnBuildAjax( settings, [], function(json) {
var aData = _fnAjaxDataSrc( oSettings, json ); var aData = _fnAjaxDataSrc( settings, json );
/* Got the data - add it to the table */ // Got the data - add it to the table
for ( i=0 ; i<aData.length ; i++ ) for ( i=0 ; i<aData.length ; i++ ) {
{ _fnAddData( settings, aData[i] );
_fnAddData( oSettings, aData[i] ); }
}
/* Reset the init display for cookie saving. We've already done a filter, and // Reset the init display for cookie saving. We've already done
* therefore cleared it before. So we need to make it appear 'fresh' // a filter, and therefore cleared it before. So we need to make
*/ // it appear 'fresh'
oSettings.iInitDisplayStart = iAjaxStart; settings.iInitDisplayStart = iAjaxStart;
_fnReDraw( oSettings ); _fnReDraw( settings );
_fnProcessingDisplay( oSettings, false ); _fnProcessingDisplay( settings, false );
_fnInitComplete( oSettings, json ); _fnInitComplete( settings, json );
}, oSettings ); }, settings );
return; }
} else {
_fnProcessingDisplay( settings, false );
/* Server-side processing init complete is done by _fnAjaxUpdateDraw */ _fnInitComplete( settings );
if ( !oSettings.oFeatures.bServerSide ) }
{
_fnProcessingDisplay( oSettings, false );
_fnInitComplete( oSettings );
} }
} }