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

Internal - store cell reference | remove _fnGetTdNodes

- We use the cell nodes form the table body in a number of places, and
  increasing with the new API, so rather than just storing a reference
  to the hidden cells, we should just store a reference to all cells and
  use them, cleaning up a number of other areas - in particular
  _fnGetTdNodes which is no longer needed

- Should do something similar for _fnGetTrNodes

- Disabled sort classes for the moment as that can be rewritten to be
  more efficient. It did use _fnGetTdNodes, but doesn't need to now.

- API fnSetColumnVis and fnUpdate will be broken at the moment, until
  merged into the new API.
This commit is contained in:
Allan Jardine 2013-04-23 09:50:59 +01:00
parent bb75f22233
commit 01bc1f728d
8 changed files with 30 additions and 97 deletions

View File

@ -21,7 +21,7 @@
*/ */
/*jslint evil: true, undef: true, browser: true */ /*jslint evil: true, undef: true, browser: true */
/*globals $,require,jQuery,define,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnNodeToColumnIndex,_fnInfoMacros,_fnBrowserDetect,_fnGetColumns,_fnHungarianMap,_fnCamelToHungarian,_fnBuildAjax,_fnAjaxDataSrc*/ /*globals $,require,jQuery,define,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnEscapeRegex,_fnDeleteIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnNodeToColumnIndex,_fnInfoMacros,_fnBrowserDetect,_fnGetColumns,_fnHungarianMap,_fnCamelToHungarian,_fnBuildAjax,_fnAjaxDataSrc*/
(/** @lends <global> */function( window, document, undefined ) { (/** @lends <global> */function( window, document, undefined ) {

View File

@ -82,7 +82,6 @@ this.oApi = {
"_fnSettingsFromNode": _fnSettingsFromNode, "_fnSettingsFromNode": _fnSettingsFromNode,
"_fnGetDataMaster": _fnGetDataMaster, "_fnGetDataMaster": _fnGetDataMaster,
"_fnGetTrNodes": _fnGetTrNodes, "_fnGetTrNodes": _fnGetTrNodes,
"_fnGetTdNodes": _fnGetTdNodes,
"_fnEscapeRegex": _fnEscapeRegex, "_fnEscapeRegex": _fnEscapeRegex,
"_fnDeleteIndex": _fnDeleteIndex, "_fnDeleteIndex": _fnDeleteIndex,
"_fnColumnOrdering": _fnColumnOrdering, "_fnColumnOrdering": _fnColumnOrdering,

View File

@ -126,16 +126,7 @@ function _fnNodeToDataIndex( oSettings, n )
*/ */
function _fnNodeToColumnIndex( oSettings, iRow, n ) function _fnNodeToColumnIndex( oSettings, iRow, n )
{ {
var anCells = _fnGetTdNodes( oSettings, iRow ); return $.inArray( n, oSettings.aoData[ iRow ].anCells );
for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
{
if ( anCells[i] === n )
{
return i;
}
}
return -1;
} }

View File

@ -13,6 +13,7 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
var var
row = oSettings.aoData[iRow], row = oSettings.aoData[iRow],
rowData = row._aData, rowData = row._aData,
cells = [],
nTr, nTd, oCol, nTr, nTd, oCol,
i, iLen; i, iLen;
@ -42,6 +43,7 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
oCol = oSettings.aoColumns[i]; oCol = oSettings.aoColumns[i];
nTd = nTrIn ? anTds[i] : document.createElement( oCol.sCellType ); nTd = nTrIn ? anTds[i] : document.createElement( oCol.sCellType );
cells.push( nTd );
// Need to create the HTML if new, or if a rendering function is defined // Need to create the HTML if new, or if a rendering function is defined
if ( !nTrIn || oCol.mRender || oCol.mData !== i ) if ( !nTrIn || oCol.mRender || oCol.mData !== i )
@ -56,7 +58,6 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
} }
// Visibility - add or remove as required // Visibility - add or remove as required
row._anHidden[i] = oCol.bVisible ? null : nTd;
if ( oCol.bVisible && ! nTrIn ) if ( oCol.bVisible && ! nTrIn )
{ {
nTr.appendChild( nTd ); nTr.appendChild( nTd );
@ -75,6 +76,7 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
} }
row.nTr = nTr; row.nTr = nTr;
row.anCells = cells;
_fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow] ); _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow] );
} }

View File

@ -301,16 +301,15 @@ function _fnGetWidestNode( oSettings, iCol )
return null; return null;
} }
if ( oSettings.aoData[iMaxIndex].nTr === null ) var data = oSettings.aoData[ iMaxIndex ];
{ return data.nTr === null ? // Might not have been created when deferred rendering
var n = document.createElement('td'); $('<td/>').html( _fnGetCellData( oSettings, iMaxIndex, iCol, 'display' ) )[0] :
n.innerHTML = _fnGetCellData( oSettings, iMaxIndex, iCol, '' ); data.anCells[ iCol ];
return n;
}
return _fnGetTdNodes(oSettings, iMaxIndex)[iCol];
} }
var __re_html_remove = /<.*?>/g;
/** /**
* Get the maximum strlen for each data column * Get the maximum strlen for each data column
* @param {object} oSettings dataTables settings object * @param {object} oSettings dataTables settings object
@ -320,13 +319,13 @@ function _fnGetWidestNode( oSettings, iCol )
*/ */
function _fnGetMaxLenString( oSettings, iCol ) function _fnGetMaxLenString( oSettings, iCol )
{ {
var iMax = -1; var s, iMax=-1, iMaxIndex = -1;
var iMaxIndex = -1;
for ( var i=0 ; i<oSettings.aoData.length ; i++ ) for ( var i=0 ; i<oSettings.aoData.length ; i++ )
{ {
var s = _fnGetCellData( oSettings, i, iCol, 'display' )+""; s = _fnGetCellData( oSettings, i, iCol, 'display' )+'';
s = s.replace( /<.*?>/g, "" ); s = s.replace( __re_html_remove, '' );
if ( s.length > iMax ) if ( s.length > iMax )
{ {
iMax = s.length; iMax = s.length;

View File

@ -434,6 +434,13 @@ function _fnSortingClasses( oSettings )
$(oSettings.aoColumns[i].nTh).addClass( oSettings.aoColumns[i].sSortingClass ); $(oSettings.aoColumns[i].nTh).addClass( oSettings.aoColumns[i].sSortingClass );
} }
} }
// @todo This is totally inefficient. It is accessing the class name of every
// cell when it really doesn't need to. It should determine which cells
// have classes to be removed (by saving the previous state or doing a check
// on the first row), and then add to the required cells. Use _pluck.
// DISABLED until this can be done, since _fnGetTdNodes has been removed.
return;
/* /*
* Apply the required classes to the table body * Apply the required classes to the table body

View File

@ -40,67 +40,6 @@ function _fnGetTrNodes ( oSettings )
} }
/**
* Return an flat array with all TD nodes for the table, or row
* @param {object} oSettings dataTables settings object
* @param {int} [iIndividualRow] aoData index to get the nodes for - optional
* if not given then the return array will contain all nodes for the table
* @returns {array} TD array
* @memberof DataTable#oApi
*/
function _fnGetTdNodes ( oSettings, iIndividualRow )
{
var anReturn = [];
var iCorrector;
var anTds, nTd;
var iRow, iRows=oSettings.aoData.length,
iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
/* Allow the collection to be limited to just one row */
if ( iIndividualRow !== undefined )
{
iStart = iIndividualRow;
iEnd = iIndividualRow+1;
}
for ( iRow=iStart ; iRow<iEnd ; iRow++ )
{
oData = oSettings.aoData[iRow];
if ( oData.nTr !== null )
{
/* get the TD child nodes - taking into account text etc nodes */
anTds = [];
nTd = oData.nTr.firstChild;
while ( nTd )
{
sNodeName = nTd.nodeName.toLowerCase();
if ( sNodeName == 'td' || sNodeName == 'th' )
{
anTds.push( nTd );
}
nTd = nTd.nextSibling;
}
iCorrector = 0;
for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
{
if ( oSettings.aoColumns[iColumn].bVisible )
{
anReturn.push( anTds[iColumn-iCorrector] );
}
else
{
anReturn.push( oData._anHidden[iColumn] );
iCorrector++;
}
}
}
}
return anReturn;
}
/** /**
* Log an error message * Log an error message
* @param {object} oSettings dataTables settings object * @param {object} oSettings dataTables settings object

View File

@ -15,6 +15,14 @@ DataTable.models.oRow = {
*/ */
"nTr": null, "nTr": null,
/**
* Array of TD elements for each row. This is null until the row has been
* created.
* @type array nodes
* @default []
*/
"anCells": null,
/** /**
* Data object from the original data source for the row. This is either * Data object from the original data source for the row. This is either
* an array if using the traditional form of DataTables, or an object if * an array if using the traditional form of DataTables, or an object if
@ -40,18 +48,6 @@ DataTable.models.oRow = {
*/ */
"_aSortData": [], "_aSortData": [],
/**
* Array of TD elements that are cached for hidden rows, so they can be
* reinserted into the table if a column is made visible again (or to act
* as a store if a column is made hidden). Only hidden columns have a
* reference in the array. For non-hidden columns the value is either
* undefined or null.
* @type array nodes
* @default []
* @private
*/
"_anHidden": [],
/** /**
* Cache of the class name that DataTables has applied to the row, so we * Cache of the class name that DataTables has applied to the row, so we
* can quickly look at this variable rather than needing to do a DOM check * can quickly look at this variable rather than needing to do a DOM check