datatables.net 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/dataTables.js CHANGED
@@ -1,11 +1,11 @@
1
- /*! DataTables 2.0.0
1
+ /*! DataTables 2.0.2
2
2
  * © SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
5
5
  /**
6
6
  * @summary DataTables
7
7
  * @description Paginate, search and order HTML tables
8
- * @version 2.0.0
8
+ * @version 2.0.2
9
9
  * @author SpryMedia Ltd
10
10
  * @contact www.datatables.net
11
11
  * @copyright SpryMedia Ltd.
@@ -317,7 +317,7 @@
317
317
  _fnCamelToHungarian( defaults.oLanguage, json );
318
318
  $.extend( true, oLanguage, json, oSettings.oInit.oLanguage );
319
319
 
320
- _fnCallbackFire( oSettings, null, 'i18n', [oSettings]);
320
+ _fnCallbackFire( oSettings, null, 'i18n', [oSettings], true);
321
321
  _fnInitialise( oSettings );
322
322
  },
323
323
  error: function () {
@@ -2355,7 +2355,7 @@
2355
2355
  */
2356
2356
  function _columnAutoClass(container, colIdx, className) {
2357
2357
  container.forEach(function (row) {
2358
- if (row[colIdx].unique) {
2358
+ if (row[colIdx] && row[colIdx].unique) {
2359
2359
  _addClass(row[colIdx].cell, className);
2360
2360
  }
2361
2361
  });
@@ -2429,24 +2429,32 @@
2429
2429
  else if ( typeof target === 'string' )
2430
2430
  {
2431
2431
  for ( k=0, kLen=columns.length ; k<kLen ; k++ ) {
2432
- if (target.indexOf(':name') !== -1) {
2432
+ if (target === '_all') {
2433
+ // Apply to all columns
2434
+ fn( k, def );
2435
+ }
2436
+ else if (target.indexOf(':name') !== -1) {
2437
+ // Column selector
2433
2438
  if (columns[k].sName === target.replace(':name', '')) {
2434
2439
  fn( k, def );
2435
2440
  }
2436
2441
  }
2437
2442
  else {
2443
+ // Cell selector
2438
2444
  headerLayout.forEach(function (row) {
2439
- var cell = $(row[k].cell);
2440
-
2441
- // Legacy support. Note that it means that we don't support
2442
- // an element name selector only, since they are treated as
2443
- // class names for 1.x compat.
2444
- if (target.match(/^[a-z][\w-]*$/i)) {
2445
- target = '.' + target;
2446
- }
2447
-
2448
- if (target === '_all' || cell.is( target )) {
2449
- fn( k, def );
2445
+ if (row[k]) {
2446
+ var cell = $(row[k].cell);
2447
+
2448
+ // Legacy support. Note that it means that we don't support
2449
+ // an element name selector only, since they are treated as
2450
+ // class names for 1.x compat.
2451
+ if (target.match(/^[a-z][\w-]*$/i)) {
2452
+ target = '.' + target;
2453
+ }
2454
+
2455
+ if (cell.is( target )) {
2456
+ fn( k, def );
2457
+ }
2450
2458
  }
2451
2459
  });
2452
2460
  }
@@ -3030,7 +3038,7 @@
3030
3038
  for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
3031
3039
  {
3032
3040
  oCol = oSettings.aoColumns[i];
3033
- create = nTrIn ? false : true;
3041
+ create = nTrIn && anTds[i] ? false : true;
3034
3042
 
3035
3043
  nTd = create ? document.createElement( oCol.sCellType ) : anTds[i];
3036
3044
 
@@ -3059,11 +3067,11 @@
3059
3067
  }
3060
3068
 
3061
3069
  // Visibility - add or remove as required
3062
- if ( oCol.bVisible && ! nTrIn )
3070
+ if ( oCol.bVisible && create )
3063
3071
  {
3064
3072
  nTr.appendChild( nTd );
3065
3073
  }
3066
- else if ( ! oCol.bVisible && nTrIn )
3074
+ else if ( ! oCol.bVisible && ! create )
3067
3075
  {
3068
3076
  nTd.parentNode.removeChild( nTd );
3069
3077
  }
@@ -3147,14 +3155,23 @@
3147
3155
  }
3148
3156
 
3149
3157
  // If no cells yet and we have content for them, then create
3150
- if ( $('th, td', target).length === 0 && (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) ) {
3151
- row = $('<tr/>')
3152
- .appendTo( target );
3158
+ if (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) {
3159
+ row = $('tr', target);
3153
3160
 
3154
- for ( i=0, ien=columns.length ; i<ien ; i++ ) {
3155
- $('<th/>')
3156
- .html( columns[i][titleProp] || '' )
3157
- .appendTo( row );
3161
+ // Add a row if needed
3162
+ if (! row.length) {
3163
+ row = $('<tr/>').appendTo(target)
3164
+ }
3165
+
3166
+ // Add the number of cells needed to make up to the number of columns
3167
+ if (row.length === 1) {
3168
+ var cells = $('td, th', row);
3169
+
3170
+ for ( i=cells.length, ien=columns.length ; i<ien ; i++ ) {
3171
+ $('<th/>')
3172
+ .html( columns[i][titleProp] || '' )
3173
+ .appendTo( row );
3174
+ }
3158
3175
  }
3159
3176
  }
3160
3177
 
@@ -3251,11 +3268,15 @@
3251
3268
  colspan++;
3252
3269
  }
3253
3270
 
3271
+ var titleSpan = $('span.dt-column-title', cell);
3272
+
3254
3273
  structure[row][column] = {
3255
3274
  cell: cell,
3256
3275
  colspan: colspan,
3257
3276
  rowspan: rowspan,
3258
- title: $('span.dt-column-title', cell).html()
3277
+ title: titleSpan.length
3278
+ ? titleSpan.html()
3279
+ : $(cell).html()
3259
3280
  };
3260
3281
  }
3261
3282
  }
@@ -3462,8 +3483,10 @@
3462
3483
  var zero = oLang.sZeroRecords;
3463
3484
  var dataSrc = _fnDataSource( settings );
3464
3485
 
3465
- if ( settings.iDraw <= 1 && (dataSrc === 'ajax' || dataSrc === 'ssp') )
3466
- {
3486
+ if (
3487
+ (settings.iDraw < 1 && dataSrc === 'ssp') ||
3488
+ (settings.iDraw <= 1 && dataSrc === 'ajax')
3489
+ ) {
3467
3490
  zero = oLang.sLoadingRecords;
3468
3491
  }
3469
3492
  else if ( oLang.sEmptyTable && settings.fnRecordsTotal() === 0 )
@@ -3509,30 +3532,34 @@
3509
3532
  'full' :
3510
3533
  splitPos[1].toLowerCase();
3511
3534
  var group = groups[ splitPos[0] ];
3512
-
3513
- // Transform to an object with a contents property
3514
- if ( $.isPlainObject( val ) ) {
3515
- // Already a group from a previous pass
3516
- if (val.contents) {
3517
- group[ align ] = val;
3535
+ var groupRun = function (contents, innerVal) {
3536
+ // If it is an object, then there can be multiple features contained in it
3537
+ if ( $.isPlainObject( innerVal ) ) {
3538
+ Object.keys(innerVal).map(function (key) {
3539
+ contents.push( {
3540
+ feature: key,
3541
+ opts: innerVal[key]
3542
+ });
3543
+ });
3518
3544
  }
3519
3545
  else {
3520
- // For objects, each property becomes an entry in the contents
3521
- // array for this insert position
3522
- group[ align ] = {
3523
- contents: Object.keys(val).map(function (key) {
3524
- return {
3525
- feature: key,
3526
- opts: val[key]
3527
- };
3528
- })
3529
- };
3546
+ contents.push(innerVal);
3547
+ }
3548
+ }
3549
+
3550
+ // Transform to an object with a contents property
3551
+ if (! group[align] || ! group[align].contents) {
3552
+ group[align] = { contents: [] };
3553
+ }
3554
+
3555
+ // Allow for an array or just a single object
3556
+ if ( Array.isArray(val)) {
3557
+ for (var i=0 ; i<val.length ; i++) {
3558
+ groupRun(group[align].contents, val[i]);
3530
3559
  }
3531
3560
  }
3532
3561
  else {
3533
- group[ align ] = {
3534
- contents: val
3535
- };
3562
+ groupRun(group[ align ].contents, val);
3536
3563
  }
3537
3564
 
3538
3565
  // And make contents an array
@@ -4034,7 +4061,12 @@
4034
4061
  oSettings.jqXHR = ajax.call( instance, data, callback, oSettings );
4035
4062
  }
4036
4063
  else if (ajax.url === '') {
4037
- callback({});
4064
+ // No url, so don't load any data. Just apply an empty data array
4065
+ // to the object for the callback.
4066
+ var empty = {};
4067
+
4068
+ DataTable.util.set(ajax.dataSrc)(empty, []);
4069
+ callback(empty);
4038
4070
  }
4039
4071
  else {
4040
4072
  // Object to extend the base settings
@@ -4413,6 +4445,9 @@
4413
4445
  search = search.toString();
4414
4446
  }
4415
4447
 
4448
+ // Remove diacritics if normalize is set up to do so
4449
+ search = _normalize(search);
4450
+
4416
4451
  if (options.exact) {
4417
4452
  return new RegExp(
4418
4453
  '^'+_fnEscapeRegex(search)+'$',
@@ -5033,12 +5068,12 @@
5033
5068
  // the content of the cell so that the width applied to the header and body
5034
5069
  // both match, but we want to hide it completely.
5035
5070
  $('th, td', headerCopy).each(function () {
5036
- $(this).children().wrapAll('<div class="dt-scroll-sizing">');
5071
+ $(this.childNodes).wrapAll('<div class="dt-scroll-sizing">');
5037
5072
  });
5038
5073
 
5039
5074
  if ( footer ) {
5040
5075
  $('th, td', footerCopy).each(function () {
5041
- $(this).children().wrapAll('<div class="dt-scroll-sizing">');
5076
+ $(this.childNodes).wrapAll('<div class="dt-scroll-sizing">');
5042
5077
  });
5043
5078
  }
5044
5079
 
@@ -5393,30 +5428,41 @@
5393
5428
 
5394
5429
  function _fnSortAttachListener(settings, node, selector, column, callback) {
5395
5430
  _fnBindAction( node, selector, function (e) {
5431
+ var run = false;
5396
5432
  var columns = column === undefined
5397
5433
  ? _fnColumnsFromHeader( e.target )
5398
5434
  : [column];
5399
5435
 
5400
5436
  if ( columns.length ) {
5401
- _fnProcessingDisplay( settings, true );
5437
+ for ( var i=0, ien=columns.length ; i<ien ; i++ ) {
5438
+ var ret = _fnSortAdd( settings, columns[i], i, e.shiftKey );
5402
5439
 
5403
- // Allow the processing display to show
5404
- setTimeout( function () {
5405
- for ( var i=0, ien=columns.length ; i<ien ; i++ ) {
5406
- var append = e.shiftKey || i > 0;
5407
-
5408
- _fnSortAdd( settings, columns[i], append );
5440
+ if (ret !== false) {
5441
+ run = true;
5442
+ }
5443
+
5444
+ // If the first entry is no sort, then subsequent
5445
+ // sort columns are ignored
5446
+ if (settings.aaSorting.length === 1 && settings.aaSorting[0][1] === '') {
5447
+ break;
5409
5448
  }
5449
+ }
5410
5450
 
5411
- _fnSort( settings );
5412
- _fnSortDisplay( settings );
5413
- _fnReDraw( settings, false, false );
5414
- _fnProcessingDisplay( settings, false );
5451
+ if (run) {
5452
+ _fnProcessingDisplay( settings, true );
5415
5453
 
5416
- if (callback) {
5417
- callback();
5418
- }
5419
- }, 0);
5454
+ // Allow the processing display to show
5455
+ setTimeout( function () {
5456
+ _fnSort( settings );
5457
+ _fnSortDisplay( settings );
5458
+ _fnReDraw( settings, false, false );
5459
+ _fnProcessingDisplay( settings, false );
5460
+
5461
+ if (callback) {
5462
+ callback();
5463
+ }
5464
+ }, 0);
5465
+ }
5420
5466
  }
5421
5467
  } );
5422
5468
  }
@@ -5428,9 +5474,23 @@
5428
5474
  function _fnSortDisplay(settings) {
5429
5475
  var display = settings.aiDisplay;
5430
5476
  var master = settings.aiDisplayMaster;
5477
+ var masterMap = {};
5478
+ var map = {};
5479
+ var i;
5431
5480
 
5432
- display.sort(function(a, b){
5433
- return master.indexOf(a) - master.indexOf(b);
5481
+ // Rather than needing an `indexOf` on master array, we can create a map
5482
+ for (i=0 ; i<master.length ; i++) {
5483
+ masterMap[master[i]] = i;
5484
+ }
5485
+
5486
+ // And then cache what would be the indexOf fom the display
5487
+ for (i=0 ; i<display.length ; i++) {
5488
+ map[display[i]] = masterMap[display[i]];
5489
+ }
5490
+
5491
+ display.sort(function(a, b){
5492
+ // Short version of this function is simply `master.indexOf(a) - master.indexOf(b);`
5493
+ return map[a] - map[b];
5434
5494
  });
5435
5495
  }
5436
5496
 
@@ -5681,12 +5741,12 @@
5681
5741
  * @param {object} settings dataTables settings object
5682
5742
  * @param {node} attachTo node to attach the handler to
5683
5743
  * @param {int} colIdx column sorting index
5684
- * @param {boolean} [append=false] Append the requested sort to the existing
5685
- * sort if true (i.e. multi-column sort)
5744
+ * @param {int} addIndex Counter
5745
+ * @param {boolean} [shift=false] Shift click add
5686
5746
  * @param {function} [callback] callback function
5687
5747
  * @memberof DataTable#oApi
5688
5748
  */
5689
- function _fnSortAdd ( settings, colIdx, append )
5749
+ function _fnSortAdd ( settings, colIdx, addIndex, shift )
5690
5750
  {
5691
5751
  var col = settings.aoColumns[ colIdx ];
5692
5752
  var sorting = settings.aaSorting;
@@ -5706,7 +5766,7 @@
5706
5766
  };
5707
5767
 
5708
5768
  if ( ! col.bSortable ) {
5709
- return;
5769
+ return false;
5710
5770
  }
5711
5771
 
5712
5772
  // Convert to 2D array if needed
@@ -5715,7 +5775,7 @@
5715
5775
  }
5716
5776
 
5717
5777
  // If appending the sort then we are multi-column sorting
5718
- if ( append && settings.oFeatures.bSortMulti ) {
5778
+ if ( (shift || addIndex) && settings.oFeatures.bSortMulti ) {
5719
5779
  // Are we already doing some kind of sort on this column?
5720
5780
  var sortIdx = _pluck(sorting, '0').indexOf(colIdx);
5721
5781
 
@@ -5735,11 +5795,18 @@
5735
5795
  sorting[sortIdx]._idx = nextSortIdx;
5736
5796
  }
5737
5797
  }
5738
- else {
5739
- // No sort on this column yet
5798
+ else if (shift) {
5799
+ // No sort on this column yet, being added by shift click
5800
+ // add it as itself
5740
5801
  sorting.push( [ colIdx, asSorting[0], 0 ] );
5741
5802
  sorting[sorting.length-1]._idx = 0;
5742
5803
  }
5804
+ else {
5805
+ // No sort on this column yet, being added from a colspan
5806
+ // so add with same direction as first column
5807
+ sorting.push( [ colIdx, sorting[0][1], 0 ] );
5808
+ sorting[sorting.length-1]._idx = 0;
5809
+ }
5743
5810
  }
5744
5811
  else if ( sorting.length && sorting[0][0] == colIdx ) {
5745
5812
  // Single column - already sorting on this column, modify the sort
@@ -8024,7 +8091,7 @@
8024
8091
  for ( var i=0, ien=data.length ; i<ien ; i++ ) {
8025
8092
  row = data[i];
8026
8093
 
8027
- if ( row._details ) {
8094
+ if ( row && row._details ) {
8028
8095
  row._details.each(function () {
8029
8096
  var el = $(this).children('td');
8030
8097
 
@@ -8043,7 +8110,7 @@
8043
8110
  }
8044
8111
 
8045
8112
  for ( var i=0, ien=data.length ; i<ien ; i++ ) {
8046
- if ( data[i]._details ) {
8113
+ if ( data[i] && data[i]._details ) {
8047
8114
  __details_remove( api, i );
8048
8115
  }
8049
8116
  }
@@ -8065,9 +8132,9 @@
8065
8132
 
8066
8133
  if ( data === undefined ) {
8067
8134
  // get
8068
- return ctx.length && this.length ?
8069
- ctx[0].aoData[ this[0] ]._details :
8070
- undefined;
8135
+ return ctx.length && this.length && ctx[0].aoData[ this[0] ]
8136
+ ? ctx[0].aoData[ this[0] ]._details
8137
+ : undefined;
8071
8138
  }
8072
8139
  else if ( data === true ) {
8073
8140
  // show
@@ -9390,6 +9457,8 @@
9390
9457
  jqTable.append( tfoot );
9391
9458
  }
9392
9459
 
9460
+ settings.colgroup.remove();
9461
+
9393
9462
  settings.aaSorting = [];
9394
9463
  settings.aaSortingFixed = [];
9395
9464
  _fnSortingClasses( settings );
@@ -9489,7 +9558,7 @@
9489
9558
  * @type string
9490
9559
  * @default Version number
9491
9560
  */
9492
- DataTable.version = "2.0.0";
9561
+ DataTable.version = "2.0.2";
9493
9562
 
9494
9563
  /**
9495
9564
  * Private data store, containing all of the settings objects that are
@@ -12234,7 +12303,7 @@
12234
12303
  } );
12235
12304
 
12236
12305
  // Common function to remove new lines, strip HTML and diacritic control
12237
- var _filterString = function (stripHtml, diacritics) {
12306
+ var _filterString = function (stripHtml, normalize) {
12238
12307
  return function (str) {
12239
12308
  if (_empty(str) || typeof str !== 'string') {
12240
12309
  return str;
@@ -12246,8 +12315,8 @@
12246
12315
  str = _stripHtml(str);
12247
12316
  }
12248
12317
 
12249
- if (diacritics) {
12250
- str = _normalize(str, true);
12318
+ if (normalize) {
12319
+ str = _normalize(str, false);
12251
12320
  }
12252
12321
 
12253
12322
  return str;
@@ -12625,7 +12694,7 @@
12625
12694
  };
12626
12695
 
12627
12696
  // prop is optional
12628
- if (! val) {
12697
+ if (val === undefined) {
12629
12698
  val = prop;
12630
12699
  prop = null;
12631
12700
  }
@@ -13284,7 +13353,7 @@
13284
13353
  if (
13285
13354
  buttonEls.length && // any buttons
13286
13355
  opts.numbers > 1 && // prevent infinite
13287
- $(host).outerHeight() >= ($(buttonEls[0]).outerHeight() * 2) - 10
13356
+ $(host).height() >= ($(buttonEls[0]).outerHeight() * 2) - 10
13288
13357
  ) {
13289
13358
  _pagingDraw(settings, host, $.extend({}, opts, { numbers: opts.numbers - 2 }));
13290
13359
  }