Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

821 Zeilen
21KB

  1. /*! RowReorder 1.2.8
  2. * 2015-2020 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * @summary RowReorder
  6. * @description Row reordering extension for DataTables
  7. * @version 1.2.8
  8. * @file dataTables.rowReorder.js
  9. * @author SpryMedia Ltd (www.sprymedia.co.uk)
  10. * @contact www.sprymedia.co.uk/contact
  11. * @copyright Copyright 2015-2020 SpryMedia Ltd.
  12. *
  13. * This source file is free software, available under the following license:
  14. * MIT license - http://datatables.net/license/mit
  15. *
  16. * This source file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  18. * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
  19. *
  20. * For details please refer to: http://www.datatables.net
  21. */
  22. (function( factory ){
  23. if ( typeof define === 'function' && define.amd ) {
  24. // AMD
  25. define( ['jquery', 'datatables.net'], function ( $ ) {
  26. return factory( $, window, document );
  27. } );
  28. }
  29. else if ( typeof exports === 'object' ) {
  30. // CommonJS
  31. module.exports = function (root, $) {
  32. if ( ! root ) {
  33. root = window;
  34. }
  35. if ( ! $ || ! $.fn.dataTable ) {
  36. $ = require('datatables.net')(root, $).$;
  37. }
  38. return factory( $, root, root.document );
  39. };
  40. }
  41. else {
  42. // Browser
  43. factory( jQuery, window, document );
  44. }
  45. }(function( $, window, document, undefined ) {
  46. 'use strict';
  47. var DataTable = $.fn.dataTable;
  48. /**
  49. * RowReorder provides the ability in DataTables to click and drag rows to
  50. * reorder them. When a row is dropped the data for the rows effected will be
  51. * updated to reflect the change. Normally this data point should also be the
  52. * column being sorted upon in the DataTable but this does not need to be the
  53. * case. RowReorder implements a "data swap" method - so the rows being
  54. * reordered take the value of the data point from the row that used to occupy
  55. * the row's new position.
  56. *
  57. * Initialisation is done by either:
  58. *
  59. * * `rowReorder` parameter in the DataTable initialisation object
  60. * * `new $.fn.dataTable.RowReorder( table, opts )` after DataTables
  61. * initialisation.
  62. *
  63. * @class
  64. * @param {object} settings DataTables settings object for the host table
  65. * @param {object} [opts] Configuration options
  66. * @requires jQuery 1.7+
  67. * @requires DataTables 1.10.7+
  68. */
  69. var RowReorder = function ( dt, opts ) {
  70. // Sanity check that we are using DataTables 1.10 or newer
  71. if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.8' ) ) {
  72. throw 'DataTables RowReorder requires DataTables 1.10.8 or newer';
  73. }
  74. // User and defaults configuration object
  75. this.c = $.extend( true, {},
  76. DataTable.defaults.rowReorder,
  77. RowReorder.defaults,
  78. opts
  79. );
  80. // Internal settings
  81. this.s = {
  82. /** @type {integer} Scroll body top cache */
  83. bodyTop: null,
  84. /** @type {DataTable.Api} DataTables' API instance */
  85. dt: new DataTable.Api( dt ),
  86. /** @type {function} Data fetch function */
  87. getDataFn: DataTable.ext.oApi._fnGetObjectDataFn( this.c.dataSrc ),
  88. /** @type {array} Pixel positions for row insertion calculation */
  89. middles: null,
  90. /** @type {Object} Cached dimension information for use in the mouse move event handler */
  91. scroll: {},
  92. /** @type {integer} Interval object used for smooth scrolling */
  93. scrollInterval: null,
  94. /** @type {function} Data set function */
  95. setDataFn: DataTable.ext.oApi._fnSetObjectDataFn( this.c.dataSrc ),
  96. /** @type {Object} Mouse down information */
  97. start: {
  98. top: 0,
  99. left: 0,
  100. offsetTop: 0,
  101. offsetLeft: 0,
  102. nodes: []
  103. },
  104. /** @type {integer} Window height cached value */
  105. windowHeight: 0,
  106. /** @type {integer} Document outer height cached value */
  107. documentOuterHeight: 0,
  108. /** @type {integer} DOM clone outer height cached value */
  109. domCloneOuterHeight: 0
  110. };
  111. // DOM items
  112. this.dom = {
  113. /** @type {jQuery} Cloned row being moved around */
  114. clone: null,
  115. /** @type {jQuery} DataTables scrolling container */
  116. dtScroll: $('div.dataTables_scrollBody', this.s.dt.table().container())
  117. };
  118. // Check if row reorder has already been initialised on this table
  119. var settings = this.s.dt.settings()[0];
  120. var exisiting = settings.rowreorder;
  121. if ( exisiting ) {
  122. return exisiting;
  123. }
  124. if ( !this.dom.dtScroll.length ) {
  125. this.dom.dtScroll = $(this.s.dt.table().container(), 'tbody')
  126. }
  127. settings.rowreorder = this;
  128. this._constructor();
  129. };
  130. $.extend( RowReorder.prototype, {
  131. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  132. * Constructor
  133. */
  134. /**
  135. * Initialise the RowReorder instance
  136. *
  137. * @private
  138. */
  139. _constructor: function ()
  140. {
  141. var that = this;
  142. var dt = this.s.dt;
  143. var table = $( dt.table().node() );
  144. // Need to be able to calculate the row positions relative to the table
  145. if ( table.css('position') === 'static' ) {
  146. table.css( 'position', 'relative' );
  147. }
  148. // listen for mouse down on the target column - we have to implement
  149. // this rather than using HTML5 drag and drop as drag and drop doesn't
  150. // appear to work on table rows at this time. Also mobile browsers are
  151. // not supported.
  152. // Use `table().container()` rather than just the table node for IE8 -
  153. // otherwise it only works once...
  154. $(dt.table().container()).on( 'mousedown.rowReorder touchstart.rowReorder', this.c.selector, function (e) {
  155. if ( ! that.c.enable ) {
  156. return;
  157. }
  158. // Ignore excluded children of the selector
  159. if ( $(e.target).is(that.c.excludedChildren) ) {
  160. return true;
  161. }
  162. var tr = $(this).closest('tr');
  163. var row = dt.row( tr );
  164. // Double check that it is a DataTable row
  165. if ( row.any() ) {
  166. that._emitEvent( 'pre-row-reorder', {
  167. node: row.node(),
  168. index: row.index()
  169. } );
  170. that._mouseDown( e, tr );
  171. return false;
  172. }
  173. } );
  174. dt.on( 'destroy.rowReorder', function () {
  175. $(dt.table().container()).off( '.rowReorder' );
  176. dt.off( '.rowReorder' );
  177. } );
  178. },
  179. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  180. * Private methods
  181. */
  182. /**
  183. * Cache the measurements that RowReorder needs in the mouse move handler
  184. * to attempt to speed things up, rather than reading from the DOM.
  185. *
  186. * @private
  187. */
  188. _cachePositions: function ()
  189. {
  190. var dt = this.s.dt;
  191. // Frustratingly, if we add `position:relative` to the tbody, the
  192. // position is still relatively to the parent. So we need to adjust
  193. // for that
  194. var headerHeight = $( dt.table().node() ).find('thead').outerHeight();
  195. // Need to pass the nodes through jQuery to get them in document order,
  196. // not what DataTables thinks it is, since we have been altering the
  197. // order
  198. var nodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() );
  199. var middles = $.map( nodes, function ( node, i ) {
  200. var top = $(node).position().top - headerHeight;
  201. return (top + top + $(node).outerHeight() ) / 2;
  202. } );
  203. this.s.middles = middles;
  204. this.s.bodyTop = $( dt.table().body() ).offset().top;
  205. this.s.windowHeight = $(window).height();
  206. this.s.documentOuterHeight = $(document).outerHeight();
  207. },
  208. /**
  209. * Clone a row so it can be floated around the screen
  210. *
  211. * @param {jQuery} target Node to be cloned
  212. * @private
  213. */
  214. _clone: function ( target )
  215. {
  216. var dt = this.s.dt;
  217. var clone = $( dt.table().node().cloneNode(false) )
  218. .addClass( 'dt-rowReorder-float' )
  219. .append('<tbody/>')
  220. .append( target.clone( false ) );
  221. // Match the table and column widths - read all sizes before setting
  222. // to reduce reflows
  223. var tableWidth = target.outerWidth();
  224. var tableHeight = target.outerHeight();
  225. var sizes = target.children().map( function () {
  226. return $(this).width();
  227. } );
  228. clone
  229. .width( tableWidth )
  230. .height( tableHeight )
  231. .find('tr').children().each( function (i) {
  232. this.style.width = sizes[i]+'px';
  233. } );
  234. // Insert into the document to have it floating around
  235. clone.appendTo( 'body' );
  236. this.dom.clone = clone;
  237. this.s.domCloneOuterHeight = clone.outerHeight();
  238. },
  239. /**
  240. * Update the cloned item's position in the document
  241. *
  242. * @param {object} e Event giving the mouse's position
  243. * @private
  244. */
  245. _clonePosition: function ( e )
  246. {
  247. var start = this.s.start;
  248. var topDiff = this._eventToPage( e, 'Y' ) - start.top;
  249. var leftDiff = this._eventToPage( e, 'X' ) - start.left;
  250. var snap = this.c.snapX;
  251. var left;
  252. var top = topDiff + start.offsetTop;
  253. if ( snap === true ) {
  254. left = start.offsetLeft;
  255. }
  256. else if ( typeof snap === 'number' ) {
  257. left = start.offsetLeft + snap;
  258. }
  259. else {
  260. left = leftDiff + start.offsetLeft;
  261. }
  262. if(top < 0) {
  263. top = 0
  264. }
  265. else if(top + this.s.domCloneOuterHeight > this.s.documentOuterHeight) {
  266. top = this.s.documentOuterHeight - this.s.domCloneOuterHeight;
  267. }
  268. this.dom.clone.css( {
  269. top: top,
  270. left: left
  271. } );
  272. },
  273. /**
  274. * Emit an event on the DataTable for listeners
  275. *
  276. * @param {string} name Event name
  277. * @param {array} args Event arguments
  278. * @private
  279. */
  280. _emitEvent: function ( name, args )
  281. {
  282. this.s.dt.iterator( 'table', function ( ctx, i ) {
  283. $(ctx.nTable).triggerHandler( name+'.dt', args );
  284. } );
  285. },
  286. /**
  287. * Get pageX/Y position from an event, regardless of if it is a mouse or
  288. * touch event.
  289. *
  290. * @param {object} e Event
  291. * @param {string} pos X or Y (must be a capital)
  292. * @private
  293. */
  294. _eventToPage: function ( e, pos )
  295. {
  296. if ( e.type.indexOf( 'touch' ) !== -1 ) {
  297. return e.originalEvent.touches[0][ 'page'+pos ];
  298. }
  299. return e[ 'page'+pos ];
  300. },
  301. /**
  302. * Mouse down event handler. Read initial positions and add event handlers
  303. * for the move.
  304. *
  305. * @param {object} e Mouse event
  306. * @param {jQuery} target TR element that is to be moved
  307. * @private
  308. */
  309. _mouseDown: function ( e, target )
  310. {
  311. var that = this;
  312. var dt = this.s.dt;
  313. var start = this.s.start;
  314. var offset = target.offset();
  315. start.top = this._eventToPage( e, 'Y' );
  316. start.left = this._eventToPage( e, 'X' );
  317. start.offsetTop = offset.top;
  318. start.offsetLeft = offset.left;
  319. start.nodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() );
  320. this._cachePositions();
  321. this._clone( target );
  322. this._clonePosition( e );
  323. this.dom.target = target;
  324. target.addClass( 'dt-rowReorder-moving' );
  325. $( document )
  326. .on( 'mouseup.rowReorder touchend.rowReorder', function (e) {
  327. that._mouseUp(e);
  328. } )
  329. .on( 'mousemove.rowReorder touchmove.rowReorder', function (e) {
  330. that._mouseMove(e);
  331. } );
  332. // Check if window is x-scrolling - if not, disable it for the duration
  333. // of the drag
  334. if ( $(window).width() === $(document).width() ) {
  335. $(document.body).addClass( 'dt-rowReorder-noOverflow' );
  336. }
  337. // Cache scrolling information so mouse move doesn't need to read.
  338. // This assumes that the window and DT scroller will not change size
  339. // during an row drag, which I think is a fair assumption
  340. var scrollWrapper = this.dom.dtScroll;
  341. this.s.scroll = {
  342. windowHeight: $(window).height(),
  343. windowWidth: $(window).width(),
  344. dtTop: scrollWrapper.length ? scrollWrapper.offset().top : null,
  345. dtLeft: scrollWrapper.length ? scrollWrapper.offset().left : null,
  346. dtHeight: scrollWrapper.length ? scrollWrapper.outerHeight() : null,
  347. dtWidth: scrollWrapper.length ? scrollWrapper.outerWidth() : null
  348. };
  349. },
  350. /**
  351. * Mouse move event handler - move the cloned row and shuffle the table's
  352. * rows if required.
  353. *
  354. * @param {object} e Mouse event
  355. * @private
  356. */
  357. _mouseMove: function ( e )
  358. {
  359. this._clonePosition( e );
  360. // Transform the mouse position into a position in the table's body
  361. var bodyY = this._eventToPage( e, 'Y' ) - this.s.bodyTop;
  362. var middles = this.s.middles;
  363. var insertPoint = null;
  364. var dt = this.s.dt;
  365. // Determine where the row should be inserted based on the mouse
  366. // position
  367. for ( var i=0, ien=middles.length ; i<ien ; i++ ) {
  368. if ( bodyY < middles[i] ) {
  369. insertPoint = i;
  370. break;
  371. }
  372. }
  373. if ( insertPoint === null ) {
  374. insertPoint = middles.length;
  375. }
  376. // Perform the DOM shuffle if it has changed from last time
  377. if ( this.s.lastInsert === null || this.s.lastInsert !== insertPoint ) {
  378. var nodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() );
  379. if ( insertPoint > this.s.lastInsert ) {
  380. this.dom.target.insertAfter( nodes[ insertPoint-1 ] );
  381. }
  382. else {
  383. this.dom.target.insertBefore( nodes[ insertPoint ] );
  384. }
  385. this._cachePositions();
  386. this.s.lastInsert = insertPoint;
  387. }
  388. this._shiftScroll( e );
  389. },
  390. /**
  391. * Mouse up event handler - release the event handlers and perform the
  392. * table updates
  393. *
  394. * @param {object} e Mouse event
  395. * @private
  396. */
  397. _mouseUp: function ( e )
  398. {
  399. var that = this;
  400. var dt = this.s.dt;
  401. var i, ien;
  402. var dataSrc = this.c.dataSrc;
  403. this.dom.clone.remove();
  404. this.dom.clone = null;
  405. this.dom.target.removeClass( 'dt-rowReorder-moving' );
  406. //this.dom.target = null;
  407. $(document).off( '.rowReorder' );
  408. $(document.body).removeClass( 'dt-rowReorder-noOverflow' );
  409. clearInterval( this.s.scrollInterval );
  410. this.s.scrollInterval = null;
  411. // Calculate the difference
  412. var startNodes = this.s.start.nodes;
  413. var endNodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() );
  414. var idDiff = {};
  415. var fullDiff = [];
  416. var diffNodes = [];
  417. var getDataFn = this.s.getDataFn;
  418. var setDataFn = this.s.setDataFn;
  419. for ( i=0, ien=startNodes.length ; i<ien ; i++ ) {
  420. if ( startNodes[i] !== endNodes[i] ) {
  421. var id = dt.row( endNodes[i] ).id();
  422. var endRowData = dt.row( endNodes[i] ).data();
  423. var startRowData = dt.row( startNodes[i] ).data();
  424. if ( id ) {
  425. idDiff[ id ] = getDataFn( startRowData );
  426. }
  427. fullDiff.push( {
  428. node: endNodes[i],
  429. oldData: getDataFn( endRowData ),
  430. newData: getDataFn( startRowData ),
  431. newPosition: i,
  432. oldPosition: $.inArray( endNodes[i], startNodes )
  433. } );
  434. diffNodes.push( endNodes[i] );
  435. }
  436. }
  437. // Create event args
  438. var eventArgs = [ fullDiff, {
  439. dataSrc: dataSrc,
  440. nodes: diffNodes,
  441. values: idDiff,
  442. triggerRow: dt.row( this.dom.target ),
  443. originalEvent: e
  444. } ];
  445. // Emit event
  446. this._emitEvent( 'row-reorder', eventArgs );
  447. var update = function () {
  448. if ( that.c.update ) {
  449. for ( i=0, ien=fullDiff.length ; i<ien ; i++ ) {
  450. var row = dt.row( fullDiff[i].node );
  451. var rowData = row.data();
  452. setDataFn( rowData, fullDiff[i].newData );
  453. // Invalidate the cell that has the same data source as the dataSrc
  454. dt.columns().every( function () {
  455. if ( this.dataSrc() === dataSrc ) {
  456. dt.cell( fullDiff[i].node, this.index() ).invalidate( 'data' );
  457. }
  458. } );
  459. }
  460. // Trigger row reordered event
  461. that._emitEvent( 'row-reordered', eventArgs );
  462. dt.draw( false );
  463. }
  464. };
  465. // Editor interface
  466. if ( this.c.editor ) {
  467. // Disable user interaction while Editor is submitting
  468. this.c.enable = false;
  469. this.c.editor
  470. .edit(
  471. diffNodes,
  472. false,
  473. $.extend( {submit: 'changed'}, this.c.formOptions )
  474. )
  475. .multiSet( dataSrc, idDiff )
  476. .one( 'preSubmitCancelled.rowReorder', function () {
  477. that.c.enable = true;
  478. that.c.editor.off( '.rowReorder' );
  479. dt.draw( false );
  480. } )
  481. .one( 'submitUnsuccessful.rowReorder', function () {
  482. dt.draw( false );
  483. } )
  484. .one( 'submitSuccess.rowReorder', function () {
  485. update();
  486. } )
  487. .one( 'submitComplete', function () {
  488. that.c.enable = true;
  489. that.c.editor.off( '.rowReorder' );
  490. } )
  491. .submit();
  492. }
  493. else {
  494. update();
  495. }
  496. },
  497. /**
  498. * Move the window and DataTables scrolling during a drag to scroll new
  499. * content into view.
  500. *
  501. * This matches the `_shiftScroll` method used in AutoFill, but only
  502. * horizontal scrolling is considered here.
  503. *
  504. * @param {object} e Mouse move event object
  505. * @private
  506. */
  507. _shiftScroll: function ( e )
  508. {
  509. var that = this;
  510. var dt = this.s.dt;
  511. var scroll = this.s.scroll;
  512. var runInterval = false;
  513. var scrollSpeed = 5;
  514. var buffer = 65;
  515. var
  516. windowY = e.pageY - document.body.scrollTop,
  517. windowVert,
  518. dtVert;
  519. // Window calculations - based on the mouse position in the window,
  520. // regardless of scrolling
  521. if ( windowY < $(window).scrollTop() + buffer ) {
  522. windowVert = scrollSpeed * -1;
  523. }
  524. else if ( windowY > scroll.windowHeight + $(window).scrollTop() - buffer ) {
  525. windowVert = scrollSpeed;
  526. }
  527. // DataTables scrolling calculations - based on the table's position in
  528. // the document and the mouse position on the page
  529. if ( scroll.dtTop !== null && e.pageY < scroll.dtTop + buffer ) {
  530. dtVert = scrollSpeed * -1;
  531. }
  532. else if ( scroll.dtTop !== null && e.pageY > scroll.dtTop + scroll.dtHeight - buffer ) {
  533. dtVert = scrollSpeed;
  534. }
  535. // This is where it gets interesting. We want to continue scrolling
  536. // without requiring a mouse move, so we need an interval to be
  537. // triggered. The interval should continue until it is no longer needed,
  538. // but it must also use the latest scroll commands (for example consider
  539. // that the mouse might move from scrolling up to scrolling left, all
  540. // with the same interval running. We use the `scroll` object to "pass"
  541. // this information to the interval. Can't use local variables as they
  542. // wouldn't be the ones that are used by an already existing interval!
  543. if ( windowVert || dtVert ) {
  544. scroll.windowVert = windowVert;
  545. scroll.dtVert = dtVert;
  546. runInterval = true;
  547. }
  548. else if ( this.s.scrollInterval ) {
  549. // Don't need to scroll - remove any existing timer
  550. clearInterval( this.s.scrollInterval );
  551. this.s.scrollInterval = null;
  552. }
  553. // If we need to run the interval to scroll and there is no existing
  554. // interval (if there is an existing one, it will continue to run)
  555. if ( ! this.s.scrollInterval && runInterval ) {
  556. this.s.scrollInterval = setInterval( function () {
  557. // Don't need to worry about setting scroll <0 or beyond the
  558. // scroll bound as the browser will just reject that.
  559. if ( scroll.windowVert ) {
  560. var top = $(document).scrollTop();
  561. $(document).scrollTop(top + scroll.windowVert);
  562. if ( top !== $(document).scrollTop() ) {
  563. var move = parseFloat(that.dom.clone.css("top"));
  564. that.dom.clone.css("top", move + scroll.windowVert);
  565. }
  566. }
  567. // DataTables scrolling
  568. if ( scroll.dtVert ) {
  569. var scroller = that.dom.dtScroll[0];
  570. if ( scroll.dtVert ) {
  571. scroller.scrollTop += scroll.dtVert;
  572. }
  573. }
  574. }, 20 );
  575. }
  576. }
  577. } );
  578. /**
  579. * RowReorder default settings for initialisation
  580. *
  581. * @namespace
  582. * @name RowReorder.defaults
  583. * @static
  584. */
  585. RowReorder.defaults = {
  586. /**
  587. * Data point in the host row's data source object for where to get and set
  588. * the data to reorder. This will normally also be the sorting column.
  589. *
  590. * @type {Number}
  591. */
  592. dataSrc: 0,
  593. /**
  594. * Editor instance that will be used to perform the update
  595. *
  596. * @type {DataTable.Editor}
  597. */
  598. editor: null,
  599. /**
  600. * Enable / disable RowReorder's user interaction
  601. * @type {Boolean}
  602. */
  603. enable: true,
  604. /**
  605. * Form options to pass to Editor when submitting a change in the row order.
  606. * See the Editor `from-options` object for details of the options
  607. * available.
  608. * @type {Object}
  609. */
  610. formOptions: {},
  611. /**
  612. * Drag handle selector. This defines the element that when dragged will
  613. * reorder a row.
  614. *
  615. * @type {String}
  616. */
  617. selector: 'td:first-child',
  618. /**
  619. * Optionally lock the dragged row's x-position. This can be `true` to
  620. * fix the position match the host table's, `false` to allow free movement
  621. * of the row, or a number to define an offset from the host table.
  622. *
  623. * @type {Boolean|number}
  624. */
  625. snapX: false,
  626. /**
  627. * Update the table's data on drop
  628. *
  629. * @type {Boolean}
  630. */
  631. update: true,
  632. /**
  633. * Selector for children of the drag handle selector that mouseDown events
  634. * will be passed through to and drag will not activate
  635. *
  636. * @type {String}
  637. */
  638. excludedChildren: 'a'
  639. };
  640. /*
  641. * API
  642. */
  643. var Api = $.fn.dataTable.Api;
  644. // Doesn't do anything - work around for a bug in DT... Not documented
  645. Api.register( 'rowReorder()', function () {
  646. return this;
  647. } );
  648. Api.register( 'rowReorder.enable()', function ( toggle ) {
  649. if ( toggle === undefined ) {
  650. toggle = true;
  651. }
  652. return this.iterator( 'table', function ( ctx ) {
  653. if ( ctx.rowreorder ) {
  654. ctx.rowreorder.c.enable = toggle;
  655. }
  656. } );
  657. } );
  658. Api.register( 'rowReorder.disable()', function () {
  659. return this.iterator( 'table', function ( ctx ) {
  660. if ( ctx.rowreorder ) {
  661. ctx.rowreorder.c.enable = false;
  662. }
  663. } );
  664. } );
  665. /**
  666. * Version information
  667. *
  668. * @name RowReorder.version
  669. * @static
  670. */
  671. RowReorder.version = '1.2.8';
  672. $.fn.dataTable.RowReorder = RowReorder;
  673. $.fn.DataTable.RowReorder = RowReorder;
  674. // Attach a listener to the document which listens for DataTables initialisation
  675. // events so we can automatically initialise
  676. $(document).on( 'init.dt.dtr', function (e, settings, json) {
  677. if ( e.namespace !== 'dt' ) {
  678. return;
  679. }
  680. var init = settings.oInit.rowReorder;
  681. var defaults = DataTable.defaults.rowReorder;
  682. if ( init || defaults ) {
  683. var opts = $.extend( {}, init, defaults );
  684. if ( init !== false ) {
  685. new RowReorder( settings, opts );
  686. }
  687. }
  688. } );
  689. return RowReorder;
  690. }));