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