diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 649d35e4..e282ab1a 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -533,16 +533,21 @@ * DOM source. * @param {object} oSettings dataTables settings object * @param {array} aData data array to be added + * @param {node} [nTr] TR element to add to the table - optional. If not given, + * DataTables will create a row automatically + * @param {array} [anTds] Array of TD|TH elements for the row - must be given + * if nTr is. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed * @memberof DataTable#oApi */ - function _fnAddData ( oSettings, aDataIn ) + function _fnAddData ( oSettings, aDataIn, nTr, anTds ) { var oCol; /* Create the object for storing information about this new row */ var iRow = oSettings.aoData.length; var oData = $.extend( true, {}, DataTable.models.oRow ); + oData._aData = aDataIn; oSettings.aoData.push( oData ); @@ -581,7 +586,7 @@ /* Create the DOM information */ if ( !oSettings.oFeatures.bDeferRender ) { - _fnCreateTr( oSettings, iRow ); + _fnCreateTr( oSettings, iRow, nTr, anTds ); } return iRow; @@ -589,167 +594,41 @@ /** - * Read in the data from the target table from the DOM + * Add one or more TR elements to the table. Generally we'd expect to + * use this for reading data from a DOM sourced table, but it could be + * used for an TR element. Note that if a TR is given, it is used (i.e. + * it is not cloned). * @param {object} oSettings dataTables settings object + * @param {array|node|jQuery} trs The TR element(s) to add to the table * @memberof DataTable#oApi */ - function _fnGatherData( oSettings ) + function _fnAddTr( oSettings, trs ) { - var iLoop, i, iLen, j, jLen, jInner, - nTds, nTrs, nTd, nTr, aLocalData, iThisIndex, - iRow, iRows, iColumn, iColumns, sNodeName, - oCol, oData; - - /* - * Process by row first - * Add the data object for the whole table - storing the tr node. Note - no point in getting - * DOM based data if we are going to go and replace it with Ajax source data. - */ - if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null ) - { - nTr = oSettings.nTBody.firstChild; - while ( nTr ) - { - if ( nTr.nodeName.toUpperCase() == "TR" ) - { - iThisIndex = oSettings.aoData.length; - nTr._DT_RowIndex = iThisIndex; - oSettings.aoData.push( $.extend( true, {}, DataTable.models.oRow, { - "nTr": nTr - } ) ); - - oSettings.aiDisplayMaster.push( iThisIndex ); - nTd = nTr.firstChild; - jInner = 0; - while ( nTd ) - { - sNodeName = nTd.nodeName.toUpperCase(); - if ( sNodeName == "TD" || sNodeName == "TH" ) - { - _fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTd.innerHTML) ); - jInner++; - } - nTd = nTd.nextSibling; - } - } - nTr = nTr.nextSibling; - } + // Allow an individual node to be passed in + if ( ! trs instanceof $ ) { + trs = $(trs); } - - /* Gather in the TD elements of the Table - note that this is basically the same as - * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet - * setup! - */ - nTrs = _fnGetTrNodes( oSettings ); - nTds = []; - for ( i=0, iLen=nTrs.length ; i=0 if successful (index of new aoData entry), -1 if failed * @memberof DataTable#oApi */ -function _fnAddData ( oSettings, aDataIn ) +function _fnAddData ( oSettings, aDataIn, nTr, anTds ) { var oCol; /* Create the object for storing information about this new row */ var iRow = oSettings.aoData.length; var oData = $.extend( true, {}, DataTable.models.oRow ); + oData._aData = aDataIn; oSettings.aoData.push( oData ); @@ -52,7 +57,7 @@ function _fnAddData ( oSettings, aDataIn ) /* Create the DOM information */ if ( !oSettings.oFeatures.bDeferRender ) { - _fnCreateTr( oSettings, iRow ); + _fnCreateTr( oSettings, iRow, nTr, anTds ); } return iRow; @@ -60,167 +65,41 @@ function _fnAddData ( oSettings, aDataIn ) /** - * Read in the data from the target table from the DOM + * Add one or more TR elements to the table. Generally we'd expect to + * use this for reading data from a DOM sourced table, but it could be + * used for an TR element. Note that if a TR is given, it is used (i.e. + * it is not cloned). * @param {object} oSettings dataTables settings object + * @param {array|node|jQuery} trs The TR element(s) to add to the table * @memberof DataTable#oApi */ -function _fnGatherData( oSettings ) +function _fnAddTr( oSettings, trs ) { - var iLoop, i, iLen, j, jLen, jInner, - nTds, nTrs, nTd, nTr, aLocalData, iThisIndex, - iRow, iRows, iColumn, iColumns, sNodeName, - oCol, oData; - - /* - * Process by row first - * Add the data object for the whole table - storing the tr node. Note - no point in getting - * DOM based data if we are going to go and replace it with Ajax source data. - */ - if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null ) - { - nTr = oSettings.nTBody.firstChild; - while ( nTr ) - { - if ( nTr.nodeName.toUpperCase() == "TR" ) - { - iThisIndex = oSettings.aoData.length; - nTr._DT_RowIndex = iThisIndex; - oSettings.aoData.push( $.extend( true, {}, DataTable.models.oRow, { - "nTr": nTr - } ) ); - - oSettings.aiDisplayMaster.push( iThisIndex ); - nTd = nTr.firstChild; - jInner = 0; - while ( nTd ) - { - sNodeName = nTd.nodeName.toUpperCase(); - if ( sNodeName == "TD" || sNodeName == "TH" ) - { - _fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTd.innerHTML) ); - jInner++; - } - nTd = nTd.nextSibling; - } - } - nTr = nTr.nextSibling; - } + // Allow an individual node to be passed in + if ( ! trs instanceof $ ) { + trs = $(trs); } - - /* Gather in the TD elements of the Table - note that this is basically the same as - * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet - * setup! - */ - nTrs = _fnGetTrNodes( oSettings ); - nTds = []; - for ( i=0, iLen=nTrs.length ; i