| 1 |
|
| 2 |
e |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
(function(window, document, undefined) { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
function fnInvertKeyValues( aIn ) |
| 35 |
{ |
| 36 |
var aRet=[]; |
| 37 |
for ( var i=0, iLen=aIn.length ; i<iLen ; i++ ) |
| 38 |
{ |
| 39 |
aRet[ aIn[i] ] = i; |
| 40 |
} |
| 41 |
return aRet; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
function fnArraySwitch( aArray, iFrom, iTo ) |
| 54 |
{ |
| 55 |
var mStore = aArray.splice( iFrom, 1 )[0]; |
| 56 |
aArray.splice( iTo, 0, mStore ); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
function fnDomSwitch( nParent, iFrom, iTo ) |
| 70 |
{ |
| 71 |
var anTags = []; |
| 72 |
for ( var i=0, iLen=nParent.childNodes.length ; i<iLen ; i++ ) |
| 73 |
{ |
| 74 |
if ( nParent.childNodes[i].nodeType == 1 ) |
| 75 |
{ |
| 76 |
anTags.push( nParent.childNodes[i] ); |
| 77 |
} |
| 78 |
} |
| 79 |
var nStore = anTags[ iFrom ]; |
| 80 |
|
| 81 |
if ( iTo !== null ) |
| 82 |
{ |
| 83 |
nParent.insertBefore( nStore, anTags[iTo] ); |
| 84 |
} |
| 85 |
else |
| 86 |
{ |
| 87 |
nParent.appendChild( nStore ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
var factory = function( $, DataTable ) { |
| 94 |
"use strict"; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
$.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo ) |
| 106 |
{ |
| 107 |
var i, iLen, j, jLen, iCols=oSettings.aoColumns.length, nTrs, oCol; |
| 108 |
var attrMap = function ( obj, prop, mapping ) { |
| 109 |
if ( ! obj[ prop ] || typeof obj[ prop ] === 'function' ) { |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
var a = obj[ prop ].split('.'); |
| 114 |
var num = a.shift(); |
| 115 |
|
| 116 |
if ( isNaN( num*1 ) ) { |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
obj[ prop ] = mapping[ num*1 ]+'.'+a.join('.'); |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
if ( iFrom == iTo ) |
| 125 |
{ |
| 126 |
|
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
if ( iFrom < 0 || iFrom >= iCols ) |
| 131 |
{ |
| 132 |
this.oApi._fnLog( oSettings, 1, "ColReorder 'from' index is out of bounds: "+iFrom ); |
| 133 |
return; |
| 134 |
} |
| 135 |
|
| 136 |
if ( iTo < 0 || iTo >= iCols ) |
| 137 |
{ |
| 138 |
this.oApi._fnLog( oSettings, 1, "ColReorder 'to' index is out of bounds: "+iTo ); |
| 139 |
return; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
var aiMapping = []; |
| 146 |
for ( i=0, iLen=iCols ; i<iLen ; i++ ) |
| 147 |
{ |
| 148 |
aiMapping[i] = i; |
| 149 |
} |
| 150 |
fnArraySwitch( aiMapping, iFrom, iTo ); |
| 151 |
var aiInvertMapping = fnInvertKeyValues( aiMapping ); |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ ) |
| 159 |
{ |
| 160 |
oSettings.aaSorting[i][0] = aiInvertMapping[ oSettings.aaSorting[i][0] ]; |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
if ( oSettings.aaSortingFixed !== null ) |
| 165 |
{ |
| 166 |
for ( i=0, iLen=oSettings.aaSortingFixed.length ; i<iLen ; i++ ) |
| 167 |
{ |
| 168 |
oSettings.aaSortingFixed[i][0] = aiInvertMapping[ oSettings.aaSortingFixed[i][0] ]; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
for ( i=0, iLen=iCols ; i<iLen ; i++ ) |
| 174 |
{ |
| 175 |
oCol = oSettings.aoColumns[i]; |
| 176 |
for ( j=0, jLen=oCol.aDataSort.length ; j<jLen ; j++ ) |
| 177 |
{ |
| 178 |
oCol.aDataSort[j] = aiInvertMapping[ oCol.aDataSort[j] ]; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
oCol.idx = aiInvertMapping[ oCol.idx ]; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
$.each( oSettings.aLastSort, function (i, val) { |
| 187 |
oSettings.aLastSort[i].src = aiInvertMapping[ val.src ]; |
| 188 |
} ); |
| 189 |
|
| 190 |
|
| 191 |
for ( i=0, iLen=iCols ; i<iLen ; i++ ) |
| 192 |
{ |
| 193 |
oCol = oSettings.aoColumns[i]; |
| 194 |
|
| 195 |
if ( typeof oCol.mData == 'number' ) { |
| 196 |
oCol.mData = aiInvertMapping[ oCol.mData ]; |
| 197 |
|
| 198 |
|
| 199 |
oSettings.oApi._fnColumnOptions( oSettings, i, {} ); |
| 200 |
} |
| 201 |
else if ( $.isPlainObject( oCol.mData ) ) { |
| 202 |
|
| 203 |
attrMap( oCol.mData, '_', aiInvertMapping ); |
| 204 |
attrMap( oCol.mData, 'filter', aiInvertMapping ); |
| 205 |
attrMap( oCol.mData, 'sort', aiInvertMapping ); |
| 206 |
attrMap( oCol.mData, 'type', aiInvertMapping ); |
| 207 |
|
| 208 |
|
| 209 |
oSettings.oApi._fnColumnOptions( oSettings, i, {} ); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
if ( oSettings.aoColumns[iFrom].bVisible ) |
| 218 |
{ |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
var iVisibleIndex = this.oApi._fnColumnIndexToVisible( oSettings, iFrom ); |
| 224 |
var iInsertBeforeIndex = null; |
| 225 |
|
| 226 |
i = iTo < iFrom ? iTo : iTo + 1; |
| 227 |
while ( iInsertBeforeIndex === null && i < iCols ) |
| 228 |
{ |
| 229 |
iInsertBeforeIndex = this.oApi._fnColumnIndexToVisible( oSettings, i ); |
| 230 |
i++; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
nTrs = oSettings.nTHead.getElementsByTagName('tr'); |
| 235 |
for ( i=0, iLen=nTrs.length ; i<iLen ; i++ ) |
| 236 |
{ |
| 237 |
fnDomSwitch( nTrs[i], iVisibleIndex, iInsertBeforeIndex ); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
if ( oSettings.nTFoot !== null ) |
| 242 |
{ |
| 243 |
nTrs = oSettings.nTFoot.getElementsByTagName('tr'); |
| 244 |
for ( i=0, iLen=nTrs.length ; i<iLen ; i++ ) |
| 245 |
{ |
| 246 |
fnDomSwitch( nTrs[i], iVisibleIndex, iInsertBeforeIndex ); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ) |
| 252 |
{ |
| 253 |
if ( oSettings.aoData[i].nTr !== null ) |
| 254 |
{ |
| 255 |
fnDomSwitch( oSettings.aoData[i].nTr, iVisibleIndex, iInsertBeforeIndex ); |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
fnArraySwitch( oSettings.aoColumns, iFrom, iTo ); |
| 265 |
|
| 266 |
|
| 267 |
fnArraySwitch( oSettings.aoPreSearchCols, iFrom, iTo ); |
| 268 |
|
| 269 |
|
| 270 |
for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ) |
| 271 |
{ |
| 272 |
var data = oSettings.aoData[i]; |
| 273 |
|
| 274 |
if ( data.anCells ) { |
| 275 |
fnArraySwitch( data.anCells, iFrom, iTo ); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
if ( data.src !== 'dom' && $.isArray( data._aData ) ) { |
| 282 |
fnArraySwitch( data._aData, iFrom, iTo ); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
for ( i=0, iLen=oSettings.aoHeader.length ; i<iLen ; i++ ) |
| 288 |
{ |
| 289 |
fnArraySwitch( oSettings.aoHeader[i], iFrom, iTo ); |
| 290 |
} |
| 291 |
|
| 292 |
if ( oSettings.aoFooter !== null ) |
| 293 |
{ |
| 294 |
for ( i=0, iLen=oSettings.aoFooter.length ; i<iLen ; i++ ) |
| 295 |
{ |
| 296 |
fnArraySwitch( oSettings.aoFooter[i], iFrom, iTo ); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
var api = new $.fn.dataTable.Api( oSettings ); |
| 302 |
api.rows().invalidate(); |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
for ( i=0, iLen=iCols ; i<iLen ; i++ ) |
| 310 |
{ |
| 311 |
$(oSettings.aoColumns[i].nTh).off('click.DT'); |
| 312 |
this.oApi._fnSortAttachListener( oSettings, oSettings.aoColumns[i].nTh, i ); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
$(oSettings.oInstance).trigger( 'column-reorder.dt', [ oSettings, { |
| 318 |
from: iFrom, |
| 319 |
to: iTo, |
| 320 |
mapping: aiInvertMapping, |
| 321 |
|
| 322 |
|
| 323 |
iFrom: iFrom, |
| 324 |
iTo: iTo, |
| 325 |
aiInvertMapping: aiInvertMapping |
| 326 |
} ] ); |
| 327 |
}; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
var ColReorder = function( dt, opts ) |
| 338 |
{ |
| 339 |
var settings = new $.fn.dataTable.Api( dt ).settings()[0]; |
| 340 |
|
| 341 |
|
| 342 |
if ( settings._colReorder ) { |
| 343 |
return settings._colReorder; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
if ( opts === true ) { |
| 348 |
opts = {}; |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
var camelToHungarian = $.fn.dataTable.camelToHungarian; |
| 353 |
if ( camelToHungarian ) { |
| 354 |
camelToHungarian( ColReorder.defaults, ColReorder.defaults, true ); |
| 355 |
camelToHungarian( ColReorder.defaults, opts || {} ); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
this.s = { |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
"dt": null, |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
"init": $.extend( true, {}, ColReorder.defaults, opts ), |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
"fixed": 0, |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
"fixedRight": 0, |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
"reorderCallback": null, |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
"mouse": { |
| 411 |
"startX": -1, |
| 412 |
"startY": -1, |
| 413 |
"offsetX": -1, |
| 414 |
"offsetY": -1, |
| 415 |
"target": -1, |
| 416 |
"targetIndex": -1, |
| 417 |
"fromIndex": -1 |
| 418 |
}, |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
"aoTargets": [] |
| 430 |
}; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
this.dom = { |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
"drag": null, |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
"pointer": null |
| 452 |
}; |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
this.s.dt = settings; |
| 457 |
this.s.dt._colReorder = this; |
| 458 |
this._fnConstruct(); |
| 459 |
|
| 460 |
return this; |
| 461 |
}; |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
ColReorder.prototype = { |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
"fnReset": function () |
| 488 |
{ |
| 489 |
var a = []; |
| 490 |
for ( var i=0, iLen=this.s.dt.aoColumns.length ; i<iLen ; i++ ) |
| 491 |
{ |
| 492 |
a.push( this.s.dt.aoColumns[i]._ColReorder_iOrigCol ); |
| 493 |
} |
| 494 |
|
| 495 |
this._fnOrderColumns( a ); |
| 496 |
|
| 497 |
return this; |
| 498 |
}, |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
"fnGetCurrentOrder": function () |
| 507 |
{ |
| 508 |
return this.fnOrder(); |
| 509 |
}, |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
"fnOrder": function ( set ) |
| 548 |
{ |
| 549 |
if ( set === undefined ) |
| 550 |
{ |
| 551 |
var a = []; |
| 552 |
for ( var i=0, iLen=this.s.dt.aoColumns.length ; i<iLen ; i++ ) |
| 553 |
{ |
| 554 |
a.push( this.s.dt.aoColumns[i]._ColReorder_iOrigCol ); |
| 555 |
} |
| 556 |
return a; |
| 557 |
} |
| 558 |
|
| 559 |
this._fnOrderColumns( fnInvertKeyValues( set ) ); |
| 560 |
|
| 561 |
return this; |
| 562 |
}, |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
"_fnConstruct": function () |
| 576 |
{ |
| 577 |
var that = this; |
| 578 |
var iLen = this.s.dt.aoColumns.length; |
| 579 |
var table = this.s.dt.nTable; |
| 580 |
var i; |
| 581 |
|
| 582 |
|
| 583 |
if ( this.s.init.iFixedColumns ) |
| 584 |
{ |
| 585 |
this.s.fixed = this.s.init.iFixedColumns; |
| 586 |
} |
| 587 |
|
| 588 |
if ( this.s.init.iFixedColumnsLeft ) |
| 589 |
{ |
| 590 |
this.s.fixed = this.s.init.iFixedColumnsLeft; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
this.s.fixedRight = this.s.init.iFixedColumnsRight ? |
| 595 |
this.s.init.iFixedColumnsRight : |
| 596 |
0; |
| 597 |
|
| 598 |
|
| 599 |
if ( this.s.init.fnReorderCallback ) |
| 600 |
{ |
| 601 |
this.s.reorderCallback = this.s.init.fnReorderCallback; |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
for ( i = 0; i < iLen; i++ ) |
| 606 |
{ |
| 607 |
if ( i > this.s.fixed-1 && i < iLen - this.s.fixedRight ) |
| 608 |
{ |
| 609 |
this._fnMouseListener( i, this.s.dt.aoColumns[i].nTh ); |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
this.s.dt.aoColumns[i]._ColReorder_iOrigCol = i; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
this.s.dt.oApi._fnCallbackReg( this.s.dt, 'aoStateSaveParams', function (oS, oData) { |
| 618 |
that._fnStateSave.call( that, oData ); |
| 619 |
}, "ColReorder_State" ); |
| 620 |
|
| 621 |
|
| 622 |
var aiOrder = null; |
| 623 |
if ( this.s.init.aiOrder ) |
| 624 |
{ |
| 625 |
aiOrder = this.s.init.aiOrder.slice(); |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
if ( this.s.dt.oLoadedState && typeof this.s.dt.oLoadedState.ColReorder != 'undefined' && |
| 630 |
this.s.dt.oLoadedState.ColReorder.length == this.s.dt.aoColumns.length ) |
| 631 |
{ |
| 632 |
aiOrder = this.s.dt.oLoadedState.ColReorder; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
if ( aiOrder ) |
| 637 |
{ |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
if ( !that.s.dt._bInitComplete ) |
| 642 |
{ |
| 643 |
var bDone = false; |
| 644 |
$(table).on( 'draw.dt.colReorder', function () { |
| 645 |
if ( !that.s.dt._bInitComplete && !bDone ) |
| 646 |
{ |
| 647 |
bDone = true; |
| 648 |
var resort = fnInvertKeyValues( aiOrder ); |
| 649 |
that._fnOrderColumns.call( that, resort ); |
| 650 |
} |
| 651 |
} ); |
| 652 |
} |
| 653 |
else |
| 654 |
{ |
| 655 |
var resort = fnInvertKeyValues( aiOrder ); |
| 656 |
that._fnOrderColumns.call( that, resort ); |
| 657 |
} |
| 658 |
} |
| 659 |
else { |
| 660 |
this._fnSetColumnIndexes(); |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
$(table).on( 'destroy.dt.colReorder', function () { |
| 665 |
$(table).off( 'destroy.dt.colReorder draw.dt.colReorder' ); |
| 666 |
$(that.s.dt.nTHead).find( '*' ).off( '.ColReorder' ); |
| 667 |
|
| 668 |
$.each( that.s.dt.aoColumns, function (i, column) { |
| 669 |
$(column.nTh).removeAttr('data-column-index'); |
| 670 |
} ); |
| 671 |
|
| 672 |
that.s.dt._colReorder = null; |
| 673 |
that.s = null; |
| 674 |
} ); |
| 675 |
}, |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
"_fnOrderColumns": function ( a ) |
| 686 |
{ |
| 687 |
if ( a.length != this.s.dt.aoColumns.length ) |
| 688 |
{ |
| 689 |
this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "ColReorder - array reorder does not "+ |
| 690 |
"match known number of columns. Skipping." ); |
| 691 |
return; |
| 692 |
} |
| 693 |
|
| 694 |
for ( var i=0, iLen=a.length ; i<iLen ; i++ ) |
| 695 |
{ |
| 696 |
var currIndex = $.inArray( i, a ); |
| 697 |
if ( i != currIndex ) |
| 698 |
{ |
| 699 |
|
| 700 |
fnArraySwitch( a, currIndex, i ); |
| 701 |
|
| 702 |
|
| 703 |
this.s.dt.oInstance.fnColReorder( currIndex, i ); |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" ) |
| 709 |
{ |
| 710 |
this.s.dt.oInstance.fnAdjustColumnSizing( false ); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt ); |
| 715 |
|
| 716 |
this._fnSetColumnIndexes(); |
| 717 |
|
| 718 |
if ( this.s.reorderCallback !== null ) |
| 719 |
{ |
| 720 |
this.s.reorderCallback.call( this ); |
| 721 |
} |
| 722 |
}, |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
"_fnStateSave": function ( oState ) |
| 735 |
{ |
| 736 |
var i, iLen, aCopy, iOrigColumn; |
| 737 |
var oSettings = this.s.dt; |
| 738 |
var columns = oSettings.aoColumns; |
| 739 |
|
| 740 |
oState.ColReorder = []; |
| 741 |
|
| 742 |
|
| 743 |
if ( oState.aaSorting ) { |
| 744 |
|
| 745 |
for ( i=0 ; i<oState.aaSorting.length ; i++ ) { |
| 746 |
oState.aaSorting[i][0] = columns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol; |
| 747 |
} |
| 748 |
|
| 749 |
var aSearchCopy = $.extend( true, [], oState.aoSearchCols ); |
| 750 |
|
| 751 |
for ( i=0, iLen=columns.length ; i<iLen ; i++ ) |
| 752 |
{ |
| 753 |
iOrigColumn = columns[i]._ColReorder_iOrigCol; |
| 754 |
|
| 755 |
|
| 756 |
oState.aoSearchCols[ iOrigColumn ] = aSearchCopy[i]; |
| 757 |
|
| 758 |
|
| 759 |
oState.abVisCols[ iOrigColumn ] = columns[i].bVisible; |
| 760 |
|
| 761 |
|
| 762 |
oState.ColReorder.push( iOrigColumn ); |
| 763 |
} |
| 764 |
} |
| 765 |
else if ( oState.order ) { |
| 766 |
|
| 767 |
for ( i=0 ; i<oState.order.length ; i++ ) { |
| 768 |
oState.order[i][0] = columns[ oState.order[i][0] ]._ColReorder_iOrigCol; |
| 769 |
} |
| 770 |
|
| 771 |
var stateColumnsCopy = $.extend( true, [], oState.columns ); |
| 772 |
|
| 773 |
for ( i=0, iLen=columns.length ; i<iLen ; i++ ) |
| 774 |
{ |
| 775 |
iOrigColumn = columns[i]._ColReorder_iOrigCol; |
| 776 |
|
| 777 |
|
| 778 |
oState.columns[ iOrigColumn ] = stateColumnsCopy[i]; |
| 779 |
|
| 780 |
|
| 781 |
oState.ColReorder.push( iOrigColumn ); |
| 782 |
} |
| 783 |
} |
| 784 |
}, |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
"_fnMouseListener": function ( i, nTh ) |
| 800 |
{ |
| 801 |
var that = this; |
| 802 |
$(nTh).on( 'mousedown.ColReorder', function (e) { |
| 803 |
e.preventDefault(); |
| 804 |
that._fnMouseDown.call( that, e, nTh ); |
| 805 |
} ); |
| 806 |
}, |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
"_fnMouseDown": function ( e, nTh ) |
| 818 |
{ |
| 819 |
var that = this; |
| 820 |
|
| 821 |
|
| 822 |
var target = $(e.target).closest('th, td'); |
| 823 |
var offset = target.offset(); |
| 824 |
var idx = parseInt( $(nTh).attr('data-column-index'), 10 ); |
| 825 |
|
| 826 |
if ( idx === undefined ) { |
| 827 |
return; |
| 828 |
} |
| 829 |
|
| 830 |
this.s.mouse.startX = e.pageX; |
| 831 |
this.s.mouse.startY = e.pageY; |
| 832 |
this.s.mouse.offsetX = e.pageX - offset.left; |
| 833 |
this.s.mouse.offsetY = e.pageY - offset.top; |
| 834 |
this.s.mouse.target = this.s.dt.aoColumns[ idx ].nTh; |
| 835 |
this.s.mouse.targetIndex = idx; |
| 836 |
this.s.mouse.fromIndex = idx; |
| 837 |
|
| 838 |
this._fnRegions(); |
| 839 |
|
| 840 |
|
| 841 |
$(document) |
| 842 |
.on( 'mousemove.ColReorder', function (e) { |
| 843 |
that._fnMouseMove.call( that, e ); |
| 844 |
} ) |
| 845 |
.on( 'mouseup.ColReorder', function (e) { |
| 846 |
that._fnMouseUp.call( that, e ); |
| 847 |
} ); |
| 848 |
}, |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
"_fnMouseMove": function ( e ) |
| 859 |
{ |
| 860 |
var that = this; |
| 861 |
|
| 862 |
if ( this.dom.drag === null ) |
| 863 |
{ |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
if ( Math.pow( |
| 869 |
Math.pow(e.pageX - this.s.mouse.startX, 2) + |
| 870 |
Math.pow(e.pageY - this.s.mouse.startY, 2), 0.5 ) < 5 ) |
| 871 |
{ |
| 872 |
return; |
| 873 |
} |
| 874 |
this._fnCreateDragNode(); |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
this.dom.drag.css( { |
| 879 |
left: e.pageX - this.s.mouse.offsetX, |
| 880 |
top: e.pageY - this.s.mouse.offsetY |
| 881 |
} ); |
| 882 |
|
| 883 |
|
| 884 |
var bSet = false; |
| 885 |
var lastToIndex = this.s.mouse.toIndex; |
| 886 |
|
| 887 |
for ( var i=1, iLen=this.s.aoTargets.length ; i<iLen ; i++ ) |
| 888 |
{ |
| 889 |
if ( e.pageX < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) ) |
| 890 |
{ |
| 891 |
this.dom.pointer.css( 'left', this.s.aoTargets[i-1].x ); |
| 892 |
this.s.mouse.toIndex = this.s.aoTargets[i-1].to; |
| 893 |
bSet = true; |
| 894 |
break; |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
if ( !bSet ) |
| 901 |
{ |
| 902 |
this.dom.pointer.css( 'left', this.s.aoTargets[this.s.aoTargets.length-1].x ); |
| 903 |
this.s.mouse.toIndex = this.s.aoTargets[this.s.aoTargets.length-1].to; |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
if ( this.s.init.bRealtime && lastToIndex !== this.s.mouse.toIndex ) { |
| 908 |
this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex ); |
| 909 |
this.s.mouse.fromIndex = this.s.mouse.toIndex; |
| 910 |
this._fnRegions(); |
| 911 |
} |
| 912 |
}, |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
"_fnMouseUp": function ( e ) |
| 923 |
{ |
| 924 |
var that = this; |
| 925 |
|
| 926 |
$(document).off( 'mousemove.ColReorder mouseup.ColReorder' ); |
| 927 |
|
| 928 |
if ( this.dom.drag !== null ) |
| 929 |
{ |
| 930 |
|
| 931 |
this.dom.drag.remove(); |
| 932 |
this.dom.pointer.remove(); |
| 933 |
this.dom.drag = null; |
| 934 |
this.dom.pointer = null; |
| 935 |
|
| 936 |
|
| 937 |
this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex ); |
| 938 |
this._fnSetColumnIndexes(); |
| 939 |
|
| 940 |
|
| 941 |
if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" ) |
| 942 |
{ |
| 943 |
this.s.dt.oInstance.fnAdjustColumnSizing( false ); |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt ); |
| 948 |
|
| 949 |
if ( this.s.reorderCallback !== null ) |
| 950 |
{ |
| 951 |
this.s.reorderCallback.call( this ); |
| 952 |
} |
| 953 |
} |
| 954 |
}, |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
"_fnRegions": function () |
| 965 |
{ |
| 966 |
var aoColumns = this.s.dt.aoColumns; |
| 967 |
|
| 968 |
this.s.aoTargets.splice( 0, this.s.aoTargets.length ); |
| 969 |
|
| 970 |
this.s.aoTargets.push( { |
| 971 |
"x": $(this.s.dt.nTable).offset().left, |
| 972 |
"to": 0 |
| 973 |
} ); |
| 974 |
|
| 975 |
var iToPoint = 0; |
| 976 |
for ( var i=0, iLen=aoColumns.length ; i<iLen ; i++ ) |
| 977 |
{ |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
if ( i != this.s.mouse.fromIndex ) |
| 983 |
{ |
| 984 |
iToPoint++; |
| 985 |
} |
| 986 |
|
| 987 |
if ( aoColumns[i].bVisible ) |
| 988 |
{ |
| 989 |
this.s.aoTargets.push( { |
| 990 |
"x": $(aoColumns[i].nTh).offset().left + $(aoColumns[i].nTh).outerWidth(), |
| 991 |
"to": iToPoint |
| 992 |
} ); |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
if ( this.s.fixedRight !== 0 ) |
| 998 |
{ |
| 999 |
this.s.aoTargets.splice( this.s.aoTargets.length - this.s.fixedRight ); |
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
if ( this.s.fixed !== 0 ) |
| 1004 |
{ |
| 1005 |
this.s.aoTargets.splice( 0, this.s.fixed ); |
| 1006 |
} |
| 1007 |
}, |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
"_fnCreateDragNode": function () |
| 1018 |
{ |
| 1019 |
var scrolling = this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== ""; |
| 1020 |
|
| 1021 |
var origCell = this.s.dt.aoColumns[ this.s.mouse.targetIndex ].nTh; |
| 1022 |
var origTr = origCell.parentNode; |
| 1023 |
var origThead = origTr.parentNode; |
| 1024 |
var origTable = origThead.parentNode; |
| 1025 |
var cloneCell = $(origCell).clone(); |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
this.dom.drag = $(origTable.cloneNode(false)) |
| 1031 |
.addClass( 'DTCR_clonedTable' ) |
| 1032 |
.append( |
| 1033 |
$(origThead.cloneNode(false)).append( |
| 1034 |
$(origTr.cloneNode(false)).append( |
| 1035 |
cloneCell[0] |
| 1036 |
) |
| 1037 |
) |
| 1038 |
) |
| 1039 |
.css( { |
| 1040 |
position: 'absolute', |
| 1041 |
top: 0, |
| 1042 |
left: 0, |
| 1043 |
width: $(origCell).outerWidth(), |
| 1044 |
height: $(origCell).outerHeight() |
| 1045 |
} ) |
| 1046 |
.appendTo( 'body' ); |
| 1047 |
|
| 1048 |
this.dom.pointer = $('<div></div>') |
| 1049 |
.addClass( 'DTCR_pointer' ) |
| 1050 |
.css( { |
| 1051 |
position: 'absolute', |
| 1052 |
top: scrolling ? |
| 1053 |
$('div.dataTables_scroll', this.s.dt.nTableWrapper).offset().top : |
| 1054 |
$(this.s.dt.nTable).offset().top, |
| 1055 |
height : scrolling ? |
| 1056 |
$('div.dataTables_scroll', this.s.dt.nTableWrapper).height() : |
| 1057 |
$(this.s.dt.nTable).height() |
| 1058 |
} ) |
| 1059 |
.appendTo( 'body' ); |
| 1060 |
}, |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
"_fnSetColumnIndexes": function () |
| 1070 |
{ |
| 1071 |
$.each( this.s.dt.aoColumns, function (i, column) { |
| 1072 |
$(column.nTh).attr('data-column-index', i); |
| 1073 |
} ); |
| 1074 |
} |
| 1075 |
}; |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
ColReorder.defaults = { |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
aiOrder: null, |
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
bRealtime: true, |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
iFixedColumnsLeft: 0, |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
iFixedColumnsRight: 0, |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
fnReorderCallback: null |
| 1139 |
}; |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
ColReorder.version = "1.2.0"; |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
$.fn.dataTable.ColReorder = ColReorder; |
| 1163 |
$.fn.DataTable.ColReorder = ColReorder; |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if ( typeof $.fn.dataTable == "function" && |
| 1168 |
typeof $.fn.dataTableExt.fnVersionCheck == "function" && |
| 1169 |
$.fn.dataTableExt.fnVersionCheck('1.10.8') ) |
| 1170 |
{ |
| 1171 |
$.fn.dataTableExt.aoFeatures.push( { |
| 1172 |
"fnInit": function( settings ) { |
| 1173 |
var table = settings.oInstance; |
| 1174 |
|
| 1175 |
if ( ! settings._colReorder ) { |
| 1176 |
var dtInit = settings.oInit; |
| 1177 |
var opts = dtInit.colReorder || dtInit.oColReorder || {}; |
| 1178 |
|
| 1179 |
new ColReorder( settings, opts ); |
| 1180 |
} |
| 1181 |
else { |
| 1182 |
table.oApi._fnLog( settings, 1, "ColReorder attempted to initialise twice. Ignoring second" ); |
| 1183 |
} |
| 1184 |
|
| 1185 |
return null; |
| 1186 |
}, |
| 1187 |
"cFeature": "R", |
| 1188 |
"sFeature": "ColReorder" |
| 1189 |
} ); |
| 1190 |
} |
| 1191 |
else { |
| 1192 |
alert( "Warning: ColReorder requires DataTables 1.10.8 or greater - www.datatables.net/download"); |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
$(document).on( 'preInit.dt.colReorder', function (e, settings) { |
| 1199 |
if ( e.namespace !== 'dt' ) { |
| 1200 |
return; |
| 1201 |
} |
| 1202 |
|
| 1203 |
var init = settings.oInit.colReorder; |
| 1204 |
var defaults = DataTable.defaults.colReorder; |
| 1205 |
|
| 1206 |
if ( init || defaults ) { |
| 1207 |
var opts = $.extend( {}, init, defaults ); |
| 1208 |
|
| 1209 |
if ( init !== false ) { |
| 1210 |
new ColReorder( settings, opts ); |
| 1211 |
} |
| 1212 |
} |
| 1213 |
} ); |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
$.fn.dataTable.Api.register( 'colReorder.reset()', function () { |
| 1218 |
return this.iterator( 'table', function ( ctx ) { |
| 1219 |
ctx._colReorder.fnReset(); |
| 1220 |
} ); |
| 1221 |
} ); |
| 1222 |
|
| 1223 |
$.fn.dataTable.Api.register( 'colReorder.order()', function ( set ) { |
| 1224 |
if ( set ) { |
| 1225 |
return this.iterator( 'table', function ( ctx ) { |
| 1226 |
ctx._colReorder.fnOrder( set ); |
| 1227 |
} ); |
| 1228 |
} |
| 1229 |
|
| 1230 |
return this.context.length ? |
| 1231 |
this.context[0]._colReorder.fnOrder() : |
| 1232 |
null; |
| 1233 |
} ); |
| 1234 |
|
| 1235 |
|
| 1236 |
return ColReorder; |
| 1237 |
}; |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
if ( typeof define === 'function' && define.amd ) { |
| 1242 |
define( ['jquery', 'datatables'], factory ); |
| 1243 |
} |
| 1244 |
else if ( typeof exports === 'object' ) { |
| 1245 |
|
| 1246 |
factory( require('jquery'), require('datatables') ); |
| 1247 |
} |
| 1248 |
else if ( jQuery && !jQuery.fn.dataTable.ColReorder ) { |
| 1249 |
|
| 1250 |
factory( jQuery, jQuery.fn.dataTable ); |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
})(window, document); |