1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-02-18 16:54:14 +01:00

Update: fnUpdate is now inline with the changes to how data can be added to the table. Rather than taking a copy of the data source, it will simply assign the data given to the row (if it is given for the row) and apply it. Documentation comments update as well.

This commit is contained in:
Allan Jardine 2012-11-01 21:56:02 +00:00
parent 065c2cc66b
commit a073515b20
2 changed files with 16 additions and 36 deletions

View File

@ -5873,7 +5873,8 @@
* self-referencing in order to make the multi column updates easier. * self-referencing in order to make the multi column updates easier.
* @param {object|array|string} mData Data to update the cell/row with * @param {object|array|string} mData Data to update the cell/row with
* @param {node|int} mRow TR element you want to update or the aoData index * @param {node|int} mRow TR element you want to update or the aoData index
* @param {int} [iColumn] The column to update (not used of mData is an array or object) * @param {int} [iColumn] The column to update, give as null or undefined to
* update a whole row.
* @param {bool} [bRedraw=true] Redraw the table or not * @param {bool} [bRedraw=true] Redraw the table or not
* @param {bool} [bAction=true] Perform pre-draw actions or not * @param {bool} [bAction=true] Perform pre-draw actions or not
* @returns {int} 0 on success, 1 on error * @returns {int} 0 on success, 1 on error
@ -5883,31 +5884,20 @@
* $(document).ready(function() { * $(document).ready(function() {
* var oTable = $('#example').dataTable(); * var oTable = $('#example').dataTable();
* oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
* oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1, 0 ); // Row * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
* } ); * } );
*/ */
this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction ) this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
{ {
var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ); var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
var i, iLen, sDisplay; var i, sDisplay;
var iRow = (typeof mRow === 'object') ? var iRow = (typeof mRow === 'object') ?
_fnNodeToDataIndex(oSettings, mRow) : mRow; _fnNodeToDataIndex(oSettings, mRow) : mRow;
if ( $.isArray(mData) && iColumn === undefined ) if ( iColumn === undefined || iColumn === null )
{ {
/* Array update - update the whole row */ /* Update the whole row */
oSettings.aoData[iRow]._aData = mData.slice(); oSettings.aoData[iRow]._aData = mData;
/* Flag to the function that we are recursing */
for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
{
this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
}
}
else if ( $.isPlainObject(mData) && iColumn === undefined )
{
/* Object update - update the whole row - assume the developer gets the object right */
oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
for ( i=0 ; i<oSettings.aoColumns.length ; i++ ) for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
{ {

View File

@ -1186,7 +1186,8 @@ this.fnSortListener = function( nNode, iColumn, fnCallback )
* self-referencing in order to make the multi column updates easier. * self-referencing in order to make the multi column updates easier.
* @param {object|array|string} mData Data to update the cell/row with * @param {object|array|string} mData Data to update the cell/row with
* @param {node|int} mRow TR element you want to update or the aoData index * @param {node|int} mRow TR element you want to update or the aoData index
* @param {int} [iColumn] The column to update (not used of mData is an array or object) * @param {int} [iColumn] The column to update, give as null or undefined to
* update a whole row.
* @param {bool} [bRedraw=true] Redraw the table or not * @param {bool} [bRedraw=true] Redraw the table or not
* @param {bool} [bAction=true] Perform pre-draw actions or not * @param {bool} [bAction=true] Perform pre-draw actions or not
* @returns {int} 0 on success, 1 on error * @returns {int} 0 on success, 1 on error
@ -1196,31 +1197,20 @@ this.fnSortListener = function( nNode, iColumn, fnCallback )
* $(document).ready(function() { * $(document).ready(function() {
* var oTable = $('#example').dataTable(); * var oTable = $('#example').dataTable();
* oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
* oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1, 0 ); // Row * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
* } ); * } );
*/ */
this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction ) this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
{ {
var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ); var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
var i, iLen, sDisplay; var i, sDisplay;
var iRow = (typeof mRow === 'object') ? var iRow = (typeof mRow === 'object') ?
_fnNodeToDataIndex(oSettings, mRow) : mRow; _fnNodeToDataIndex(oSettings, mRow) : mRow;
if ( $.isArray(mData) && iColumn === undefined ) if ( iColumn === undefined || iColumn === null )
{ {
/* Array update - update the whole row */ /* Update the whole row */
oSettings.aoData[iRow]._aData = mData.slice(); oSettings.aoData[iRow]._aData = mData;
/* Flag to the function that we are recursing */
for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
{
this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
}
}
else if ( $.isPlainObject(mData) && iColumn === undefined )
{
/* Object update - update the whole row - assume the developer gets the object right */
oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
for ( i=0 ; i<oSettings.aoColumns.length ; i++ ) for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
{ {