|
1 |
| -/*! ColReorder 1.1.1 |
| 1 | +/*! ColReorder 1.1.2 |
2 | 2 | * ©2010-2014 SpryMedia Ltd - datatables.net/license
|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * @summary ColReorder
|
7 | 7 | * @description Provide the ability to reorder columns in a DataTable
|
8 |
| - * @version 1.1.1 |
| 8 | + * @version 1.1.2 |
9 | 9 | * @file dataTables.colReorder.js
|
10 | 10 | * @author SpryMedia Ltd (www.sprymedia.co.uk)
|
11 | 11 | * @contact www.sprymedia.co.uk/contact
|
@@ -111,6 +111,20 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo )
|
111 | 111 | {
|
112 | 112 | var v110 = $.fn.dataTable.Api ? true : false;
|
113 | 113 | var i, iLen, j, jLen, iCols=oSettings.aoColumns.length, nTrs, oCol;
|
| 114 | + var attrMap = function ( obj, prop, mapping ) { |
| 115 | + if ( ! obj[ prop ] ) { |
| 116 | + return; |
| 117 | + } |
| 118 | + |
| 119 | + var a = obj[ prop ].split('.'); |
| 120 | + var num = a.shift(); |
| 121 | + |
| 122 | + if ( isNaN( num*1 ) ) { |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + obj[ prop ] = mapping[ num*1 ]+'.'+a.join('.'); |
| 127 | + }; |
114 | 128 |
|
115 | 129 | /* Sanity check in the input */
|
116 | 130 | if ( iFrom == iTo )
|
@@ -187,9 +201,20 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo )
|
187 | 201 | for ( i=0, iLen=iCols ; i<iLen ; i++ )
|
188 | 202 | {
|
189 | 203 | oCol = oSettings.aoColumns[i];
|
| 204 | + |
190 | 205 | if ( typeof oCol.mData == 'number' ) {
|
191 | 206 | oCol.mData = aiInvertMapping[ oCol.mData ];
|
192 | 207 |
|
| 208 | + // regenerate the get / set functions |
| 209 | + oSettings.oApi._fnColumnOptions( oSettings, i, {} ); |
| 210 | + } |
| 211 | + else if ( $.isPlainObject( oCol.mData ) ) { |
| 212 | + // HTML5 data sourced |
| 213 | + attrMap( oCol.mData, '_', aiInvertMapping ); |
| 214 | + attrMap( oCol.mData, 'filter', aiInvertMapping ); |
| 215 | + attrMap( oCol.mData, 'sort', aiInvertMapping ); |
| 216 | + attrMap( oCol.mData, 'type', aiInvertMapping ); |
| 217 | + |
193 | 218 | // regenerate the get / set functions
|
194 | 219 | oSettings.oApi._fnColumnOptions( oSettings, i, {} );
|
195 | 220 | }
|
@@ -366,8 +391,10 @@ var ColReorder = function( dt, opts )
|
366 | 391 | }
|
367 | 392 |
|
368 | 393 | // Convert from camelCase to Hungarian, just as DataTables does
|
369 |
| - if ( $.fn.dataTable.camelToHungarian ) { |
370 |
| - $.fn.dataTable.camelToHungarian( ColReorder.defaults, opts || {} ); |
| 394 | + var camelToHungarian = $.fn.dataTable.camelToHungarian; |
| 395 | + if ( camelToHungarian ) { |
| 396 | + camelToHungarian( ColReorder.defaults, ColReorder.defaults, true ); |
| 397 | + camelToHungarian( ColReorder.defaults, opts || {} ); |
371 | 398 | }
|
372 | 399 |
|
373 | 400 |
|
@@ -732,28 +759,51 @@ ColReorder.prototype = {
|
732 | 759 | {
|
733 | 760 | var i, iLen, aCopy, iOrigColumn;
|
734 | 761 | var oSettings = this.s.dt;
|
| 762 | + var columns = oSettings.aoColumns; |
| 763 | + |
| 764 | + oState.ColReorder = []; |
735 | 765 |
|
736 | 766 | /* Sorting */
|
737 |
| - for ( i=0 ; i<oState.aaSorting.length ; i++ ) |
738 |
| - { |
739 |
| - oState.aaSorting[i][0] = oSettings.aoColumns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol; |
740 |
| - } |
| 767 | + if ( oState.aaSorting ) { |
| 768 | + // 1.10.0- |
| 769 | + for ( i=0 ; i<oState.aaSorting.length ; i++ ) { |
| 770 | + oState.aaSorting[i][0] = columns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol; |
| 771 | + } |
741 | 772 |
|
742 |
| - var aSearchCopy = $.extend( true, [], oState.aoSearchCols ); |
743 |
| - oState.ColReorder = []; |
| 773 | + var aSearchCopy = $.extend( true, [], oState.aoSearchCols ); |
744 | 774 |
|
745 |
| - for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ ) |
746 |
| - { |
747 |
| - iOrigColumn = oSettings.aoColumns[i]._ColReorder_iOrigCol; |
| 775 | + for ( i=0, iLen=columns.length ; i<iLen ; i++ ) |
| 776 | + { |
| 777 | + iOrigColumn = columns[i]._ColReorder_iOrigCol; |
748 | 778 |
|
749 |
| - /* Column filter */ |
750 |
| - oState.aoSearchCols[ iOrigColumn ] = aSearchCopy[i]; |
| 779 | + /* Column filter */ |
| 780 | + oState.aoSearchCols[ iOrigColumn ] = aSearchCopy[i]; |
751 | 781 |
|
752 |
| - /* Visibility */ |
753 |
| - oState.abVisCols[ iOrigColumn ] = oSettings.aoColumns[i].bVisible; |
| 782 | + /* Visibility */ |
| 783 | + oState.abVisCols[ iOrigColumn ] = columns[i].bVisible; |
754 | 784 |
|
755 |
| - /* Column reordering */ |
756 |
| - oState.ColReorder.push( iOrigColumn ); |
| 785 | + /* Column reordering */ |
| 786 | + oState.ColReorder.push( iOrigColumn ); |
| 787 | + } |
| 788 | + } |
| 789 | + else if ( oState.order ) { |
| 790 | + // 1.10.1+ |
| 791 | + for ( i=0 ; i<oState.order.length ; i++ ) { |
| 792 | + oState.order[i][0] = columns[ oState.order[i][0] ]._ColReorder_iOrigCol; |
| 793 | + } |
| 794 | + |
| 795 | + var stateColumnsCopy = $.extend( true, [], oState.columns ); |
| 796 | + |
| 797 | + for ( i=0, iLen=columns.length ; i<iLen ; i++ ) |
| 798 | + { |
| 799 | + iOrigColumn = columns[i]._ColReorder_iOrigCol; |
| 800 | + |
| 801 | + /* Columns */ |
| 802 | + oState.columns[ iOrigColumn ] = stateColumnsCopy[i]; |
| 803 | + |
| 804 | + /* Column reordering */ |
| 805 | + oState.ColReorder.push( iOrigColumn ); |
| 806 | + } |
757 | 807 | }
|
758 | 808 | },
|
759 | 809 |
|
@@ -1236,7 +1286,7 @@ ColReorder.defaults = {
|
1236 | 1286 | * @type String
|
1237 | 1287 | * @default As code
|
1238 | 1288 | */
|
1239 |
| -ColReorder.version = "1.1.1"; |
| 1289 | +ColReorder.version = "1.1.2"; |
1240 | 1290 |
|
1241 | 1291 |
|
1242 | 1292 |
|
@@ -1306,7 +1356,11 @@ return ColReorder;
|
1306 | 1356 |
|
1307 | 1357 | // Define as an AMD module if possible
|
1308 | 1358 | if ( typeof define === 'function' && define.amd ) {
|
1309 |
| - define( 'datatables-colreorder', ['jquery', 'datatables'], factory ); |
| 1359 | + define( ['jquery', 'datatables'], factory ); |
| 1360 | +} |
| 1361 | +else if ( typeof exports === 'object' ) { |
| 1362 | + // Node/CommonJS |
| 1363 | + factory( require('jquery'), require('datatables') ); |
1310 | 1364 | }
|
1311 | 1365 | else if ( jQuery && !jQuery.fn.dataTable.ColReorder ) {
|
1312 | 1366 | // Otherwise simply initialise as normal, stopping multiple evaluation
|
|
0 commit comments