Update ColReorder Datatables plugin

This commit is contained in:
Martin Konecny 2013-02-14 17:48:32 -05:00
parent b30f67b24b
commit 4f3ea3f406

View file

@ -1,8 +1,8 @@
/*
* File: ColReorder.js
* Version: 1.0.5
* Version: 1.0.8
* CVS: $Id$
* Description: Controls for column visiblity in DataTables
* Description: Allow columns to be reordered in a DataTable
* Author: Allan Jardine (www.sprymedia.co.uk)
* Created: Wed Sep 15 18:23:29 BST 2010
* Modified: $Date$ by $Author$
@ -174,10 +174,10 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo )
for ( i=0, iLen=iCols ; i<iLen ; i++ )
{
oCol = oSettings.aoColumns[i];
if ( typeof oCol.mDataProp == 'number' ) {
oCol.mDataProp = aiInvertMapping[ oCol.mDataProp ];
oCol.fnGetData = oSettings.oApi._fnGetObjectDataFn( oCol.mDataProp );
oCol.fnSetData = oSettings.oApi._fnSetObjectDataFn( oCol.mDataProp );
if ( typeof oCol.mData == 'number' ) {
oCol.mData = aiInvertMapping[ oCol.mData ];
oCol.fnGetData = oSettings.oApi._fnGetObjectDataFn( oCol.mData );
oCol.fnSetData = oSettings.oApi._fnSetObjectDataFn( oCol.mData );
}
}
@ -274,13 +274,12 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo )
}
/*
* Any extra operations for the other plug-ins
*/
if ( typeof ColVis != 'undefined' )
{
ColVis.fnRebuild( oSettings.oInstance );
}
/* Fire an event so other plug-ins can update */
$(oSettings.oInstance).trigger( 'column-reorder', [ oSettings, {
"iFrom": iFrom,
"iTo": iTo,
"aiInvertMapping": aiInvertMapping
} ] );
if ( typeof oSettings.oInstance._oPluginFixedHeader != 'undefined' )
{
@ -295,10 +294,10 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo )
* ColReorder provides column visiblity control for DataTables
* @class ColReorder
* @constructor
* @param {object} DataTables object
* @param {object} DataTables settings object
* @param {object} ColReorder options
*/
ColReorder = function( oTable, oOpts )
ColReorder = function( oDTSettings, oOpts )
{
/* Santiy check that we are a new instance */
if ( !this.CLASS || this.CLASS != "ColReorder" )
@ -401,9 +400,12 @@ ColReorder = function( oTable, oOpts )
/* Constructor logic */
this.s.dt = oTable.fnSettings();
this.s.dt = oDTSettings.oInstance.fnSettings();
this._fnConstruct();
/* Add destroy callback */
oDTSettings.oApi._fnCallbackReg(oDTSettings, 'aoDestroyCallback', jQuery.proxy(this._fnDestroy, this), 'ColReorder');
/* Store the instance for later use */
ColReorder.aoInstances.push( this );
return this;
@ -527,7 +529,7 @@ ColReorder.prototype = {
{
if ( a.length != this.s.dt.aoColumns.length )
{
this.s.dt.oInstance.oApi._fnLog( oDTSettings, 1, "ColReorder - array reorder does not "+
this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "ColReorder - array reorder does not "+
"match known number of columns. Skipping." );
return;
}
@ -611,8 +613,8 @@ ColReorder.prototype = {
{
var that = this;
$(nTh).bind( 'mousedown.ColReorder', function (e) {
e.preventDefault();
that._fnMouseDown.call( that, e, nTh );
return false;
} );
},
@ -812,7 +814,7 @@ ColReorder.prototype = {
}
$('thead tr:eq(0)', this.dom.drag).each( function () {
$('th:not(:eq('+that.s.mouse.targetIndex+'))', this).remove();
$('th', this).eq(that.s.mouse.targetIndex).siblings().remove();
} );
$('tr', this.dom.drag).height( $('tr:eq(0)', that.s.dt.nTHead).height() );
@ -845,6 +847,29 @@ ColReorder.prototype = {
document.body.appendChild( this.dom.pointer );
document.body.appendChild( this.dom.drag );
},
/**
* Clean up ColReorder memory references and event handlers
* @method _fnDestroy
* @returns void
* @private
*/
"_fnDestroy": function ()
{
for ( var i=0, iLen=ColReorder.aoInstances.length ; i<iLen ; i++ )
{
if ( ColReorder.aoInstances[i] === this )
{
ColReorder.aoInstances.splice( i, 1 );
break;
}
}
$(this.s.dt.nTHead).find( '*' ).unbind( '.ColReorder' );
this.s.dt.oInstance._oPluginColReorder = null;
this.s = null;
}
};
@ -914,7 +939,7 @@ ColReorder.prototype.CLASS = "ColReorder";
* @type String
* @default As code
*/
ColReorder.VERSION = "1.0.5";
ColReorder.VERSION = "1.0.8";
ColReorder.prototype.VERSION = ColReorder.VERSION;
@ -930,7 +955,7 @@ ColReorder.prototype.VERSION = ColReorder.VERSION;
*/
if ( typeof $.fn.dataTable == "function" &&
typeof $.fn.dataTableExt.fnVersionCheck == "function" &&
$.fn.dataTableExt.fnVersionCheck('1.9.0') )
$.fn.dataTableExt.fnVersionCheck('1.9.3') )
{
$.fn.dataTableExt.aoFeatures.push( {
"fnInit": function( oDTSettings ) {
@ -938,7 +963,7 @@ if ( typeof $.fn.dataTable == "function" &&
if ( typeof oTable._oPluginColReorder == 'undefined' ) {
var opts = typeof oDTSettings.oInit.oColReorder != 'undefined' ?
oDTSettings.oInit.oColReorder : {};
oTable._oPluginColReorder = new ColReorder( oDTSettings.oInstance, opts );
oTable._oPluginColReorder = new ColReorder( oDTSettings, opts );
} else {
oTable.oApi._fnLog( oDTSettings, 1, "ColReorder attempted to initialise twice. Ignoring second" );
}
@ -951,7 +976,7 @@ if ( typeof $.fn.dataTable == "function" &&
}
else
{
alert( "Warning: ColReorder requires DataTables 1.9.0 or greater - www.datatables.net/download");
alert( "Warning: ColReorder requires DataTables 1.9.3 or greater - www.datatables.net/download");
}
})(jQuery, window, document);