Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 26ad65d

Browse files
committed
Correct Bootstrap ColVis + ColReorder + TableTools + Add new API withDOM
1 parent 0299f26 commit 26ad65d

11 files changed

+180
-35
lines changed

demo/allInOne.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
})
4040

4141
// Add Table tools compatibility
42-
.withTableTools('https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf')
42+
.withTableTools('vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
4343
.withTableToolsButtons([
4444
'copy',
4545
'print', {

demo/partials/all_in_one.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ <h1><i class="fa fa-play"></i>&nbsp;All in one</h1>
6060
})
6161

6262
// Add Table tools compatibility
63-
.withTableTools('https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf')
63+
.withTableTools('vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
6464
.withTableToolsButtons([
6565
'copy',
6666
'print', {

demo/partials/api.html

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ <h3><code>DTOptionsBuilder</code></h3>
347347
"sDom": "Rlfrtip"
348348
}
349349
</div>
350+
<p class="text-info">
351+
<i class="fa fa-info-circle"></i>&nbsp;By calling this API, the letter <code>R</code> is appended to the <a href="http://datatables.net/examples/basic_init/dom.html">DOM positioning</a>.
352+
</p>
350353
</td>
351354
</tr>
352355
<tr>
@@ -457,6 +460,9 @@ <h3><code>DTOptionsBuilder</code></h3>
457460
"sDom": "Clfrtip"
458461
}
459462
</div>
463+
<p class="text-info">
464+
<i class="fa fa-info-circle"></i>&nbsp;By calling this API, the letter <code>C</code> is appended to the <a href="http://datatables.net/examples/basic_init/dom.html">DOM positioning</a>.
465+
</p>
460466
</td>
461467
</tr>
462468
<tr>
@@ -528,7 +534,7 @@ <h3><code>DTOptionsBuilder</code></h3>
528534
angular.module('myModule', ['datatables'])
529535
.controller('myCtrl', function ($scope, DTOptionsBuilder) {
530536
$scope.dtOptions = DTOptionsBuilder.fromSource('data.json')
531-
.withTableTools('https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf')
537+
.withTableTools('vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
532538
});
533539
</div>
534540
<p class="text-danger">
@@ -542,10 +548,13 @@ <h3><code>DTOptionsBuilder</code></h3>
542548
"sAjaxSource": "data.json",
543549
"sDom": "Tlfrtip",
544550
"oTableTools": {
545-
"sSwfPath": "https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf"
551+
"sSwfPath": "vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf"
546552
}
547553
}
548554
</div>
555+
<p class="text-info">
556+
<i class="fa fa-info-circle"></i>&nbsp;By calling this API, the letter <code>T</code> is appended to the <a href="http://datatables.net/examples/basic_init/dom.html">DOM positioning</a>.
557+
</p>
549558
</td>
550559
</tr>
551560
<tr>
@@ -557,7 +566,7 @@ <h3><code>DTOptionsBuilder</code></h3>
557566
angular.module('myModule', ['datatables'])
558567
.controller('myCtrl', function ($scope, DTOptionsBuilder) {
559568
$scope.dtOptions = DTOptionsBuilder.fromSource('data.json')
560-
.withTableTools('https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf')
569+
.withTableTools('vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
561570
// Single row selection at a time
562571
.withTableTools('sRowSelect', 'single');
563572
});
@@ -570,7 +579,7 @@ <h3><code>DTOptionsBuilder</code></h3>
570579
"sAjaxSource": "data.json",
571580
"sDom": "Tlfrtip",
572581
"oTableTools": {
573-
"sSwfPath": "https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf",
582+
"sSwfPath": "vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf",
574583
"sRowSelect": "single"
575584
}
576585
}
@@ -586,7 +595,7 @@ <h3><code>DTOptionsBuilder</code></h3>
586595
angular.module('myModule', ['datatables'])
587596
.controller('myCtrl', function ($scope, DTOptionsBuilder) {
588597
$scope.dtOptions = DTOptionsBuilder.fromSource('data.json')
589-
.withTableTools('https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf')
598+
.withTableTools('vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
590599
// Single row selection at a time
591600
.withTableToolsButtons([
592601
'copy',
@@ -620,6 +629,23 @@ <h3><code>DTOptionsBuilder</code></h3>
620629
</div>
621630
</td>
622631
</tr>
632+
<tr>
633+
<td><code>DTOptions</code></td>
634+
<td><code>withDOM(sDom)</code></td>
635+
<td>
636+
<p>Override the <a href="http://datatables.net/examples/basic_init/dom.html">DOM positioning</a> of the DataTable.</p>
637+
<div hljs language="js">
638+
angular.module('myModule', ['datatables'])
639+
.controller('myCtrl', function ($scope, DTOptionsBuilder) {
640+
$scope.dtOptions = DTOptionsBuilder.newOptions()
641+
.withDOM('pitrfl');
642+
});
643+
</div>
644+
<p class="text-info">
645+
<i class="fa fa-info-circle"></i>&nbsp;By default, the DOM positioning is set to <code>lfrtip</code>.
646+
</p>
647+
</td>
648+
</tr>
623649
</tbody>
624650
</table>
625651

demo/partials/with_options.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ <h1><i class="fa fa-play"></i>&nbsp;With options</h1>
7979
<tab heading="JS">
8080
<div hljs language="js">
8181
angular.module('datatablesSampleApp', ['datatables']).controller('withOptionsCtrl', function ($scope, DTOptionsBuilder) {
82-
$scope.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers').withDisplayLength(2);
82+
$scope.dtOptions = DTOptionsBuilder.newOptions()
83+
.withPaginationType('full_numbers')
84+
.withDisplayLength(2)
85+
.withDOM('pitrfl');
8386
});
8487
</div>
8588
</tab>

demo/withOptions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
(function() {
66
'use strict';
77
angular.module('datatablesSampleApp').controller('withOptionsCtrl', function ($scope, DTOptionsBuilder) {
8-
$scope.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers').withDisplayLength(2);
8+
$scope.dtOptions = DTOptionsBuilder.newOptions()
9+
.withPaginationType('full_numbers')
10+
.withDisplayLength(2)
11+
.withDOM('pitrfl');
912
});
10-
})();
13+
})();

demo/withTableTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$scope.dtOptions = DTOptionsBuilder
99
.fromSource('data.json')
1010
// Add Table tools compatibility
11-
.withTableTools('https://github.com/DataTables/TableTools/raw/master/swf/copy_csv_xls_pdf.swf')
11+
.withTableTools('vendor/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
1212
.withTableToolsButtons([
1313
'copy',
1414
'print', {

dist/angular-datatables.js

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010
(function (window, document, $, angular) {
1111
'use strict';
1212
angular.module('datatable.bootstrap.tabletools', []).service('$DTBootstrapTableTools', function () {
13-
var _initializedTableTools = false;
13+
var _initializedTableTools = false, _savedFn = {};
14+
var _saveFnToBeOverrided = function () {
15+
if ($.fn.DataTable.TableTools) {
16+
_savedFn.TableTools = {
17+
classes: angular.copy($.fn.DataTable.TableTools.classes),
18+
oTags: angular.copy($.fn.DataTable.TableTools.DEFAULTS.oTags)
19+
};
20+
}
21+
};
1422
this.integrate = function () {
1523
if (!_initializedTableTools) {
24+
_saveFnToBeOverrided();
1625
/*
1726
* TableTools Bootstrap compatibility
1827
* Required TableTools 2.1+
@@ -47,6 +56,13 @@
4756
_initializedTableTools = true;
4857
}
4958
};
59+
this.deIntegrate = function () {
60+
if (_initializedTableTools && $.fn.DataTable.TableTools && _savedFn.TableTools) {
61+
$.extend(true, $.fn.DataTable.TableTools.classes, _savedFn.TableTools.classes);
62+
$.extend(true, $.fn.DataTable.TableTools.DEFAULTS.oTags, _savedFn.TableTools.oTags);
63+
_initializedTableTools = false;
64+
}
65+
};
5066
});
5167
angular.module('datatables.bootstrap.colvis', []).service('$DTBootstrapColVis', function () {
5268
var _initializedColVis = false;
@@ -69,15 +85,22 @@
6985
angular.module('datatables.bootstrap', [
7086
'datatable.bootstrap.tabletools',
7187
'datatables.bootstrap.colvis'
72-
]).service('$DTBootstrap', [
88+
]).value('DT_BOOTSTRAP_DEFAULT_DOM', '<\'row\'<\'col-xs-6\'l><\'col-xs-6\'f>r>t<\'row\'<\'col-xs-6\'i><\'col-xs-6\'p>>').service('$DTBootstrap', [
7389
'$DTBootstrapTableTools',
7490
'$DTBootstrapColVis',
75-
function ($DTBootstrapTableTools, $DTBootstrapColVis) {
91+
'DT_BOOTSTRAP_DEFAULT_DOM',
92+
function ($DTBootstrapTableTools, $DTBootstrapColVis, DT_BOOTSTRAP_DEFAULT_DOM) {
7693
var _initialized = false, _drawCallbackFunctionList = [], _savedFn = {};
7794
var _saveFnToBeOverrided = function () {
7895
_savedFn.oStdClasses = angular.copy($.fn.dataTableExt.oStdClasses);
7996
_savedFn.fnPagingInfo = $.fn.dataTableExt.oApi.fnPagingInfo;
8097
_savedFn.renderer = angular.copy($.fn.DataTable.ext.renderer);
98+
if ($.fn.DataTable.TableTools) {
99+
_savedFn.TableTools = {
100+
classes: angular.copy($.fn.DataTable.TableTools.classes),
101+
oTags: angular.copy($.fn.DataTable.TableTools.DEFAULTS.oTags)
102+
};
103+
}
81104
}, _revertToDTFn = function () {
82105
$.extend($.fn.dataTableExt.oStdClasses, _savedFn.oStdClasses);
83106
$.fn.dataTableExt.oApi.fnPagingInfo = _savedFn.fnPagingInfo;
@@ -223,18 +246,33 @@
223246
}
224247
};
225248
var _init = function () {
226-
if (!_initialized) {
227-
_saveFnToBeOverrided();
228-
_overrideClasses();
229-
_overridePagingInfo();
230-
_overridePagination();
231-
_addDrawCallbackFunction(function () {
232-
$('div.dataTables_filter').find('input').addClass('form-control');
233-
$('div.dataTables_length').find('select').addClass('form-control');
234-
});
235-
_initialized = true;
236-
}
237-
};
249+
if (!_initialized) {
250+
_saveFnToBeOverrided();
251+
_overrideClasses();
252+
_overridePagingInfo();
253+
_overridePagination();
254+
_addDrawCallbackFunction(function () {
255+
$('div.dataTables_filter').find('input').addClass('form-control');
256+
$('div.dataTables_length').find('select').addClass('form-control');
257+
});
258+
_initialized = true;
259+
}
260+
}, _setDom = function (options) {
261+
if (!options.hasOverrideDom) {
262+
var sDom = DT_BOOTSTRAP_DEFAULT_DOM;
263+
if (options.hasColReorder) {
264+
sDom = 'R' + sDom;
265+
}
266+
if (options.hasColVis) {
267+
sDom = 'C' + sDom;
268+
}
269+
if (options.hasTableTools) {
270+
sDom = 'T' + sDom;
271+
}
272+
return sDom;
273+
}
274+
return options.sDom;
275+
};
238276
/**
239277
* Integrate Bootstrap
240278
* @param options the datatables options
@@ -243,8 +281,7 @@
243281
_init();
244282
$DTBootstrapTableTools.integrate();
245283
$DTBootstrapColVis.integrate(_addDrawCallbackFunction);
246-
// TODO: It currently applies the bootstrap integration to all tables...
247-
options.sDom = '<\'row\'<\'col-xs-6\'l><\'col-xs-6\'f>r>t<\'row\'<\'col-xs-6\'i><\'col-xs-6\'p>>';
284+
options.sDom = _setDom(options);
248285
if (angular.isUndefined(options.fnDrawCallback)) {
249286
// Call every drawcallback functions
250287
options.fnDrawCallback = function () {
@@ -257,6 +294,7 @@
257294
this.deIntegrate = function () {
258295
if (_initialized) {
259296
_revertToDTFn();
297+
$DTBootstrapTableTools.deIntegrate();
260298
_initialized = false;
261299
}
262300
};
@@ -565,6 +603,10 @@
565603
this.sAjaxSource = sAjaxSource;
566604
this.fnPromise = fnPromise;
567605
this.integrateBootstrap = false;
606+
this.hasColVis = false;
607+
this.hasColReorder = false;
608+
this.hasTableTools = false;
609+
this.hasOverrideDom = false;
568610
/**
569611
* Optional class to handle undefined or null
570612
* @param obj the object to wrap
@@ -702,6 +744,16 @@
702744
this.fnPromise = fnPromise;
703745
return this;
704746
};
747+
/**
748+
* Set the Dom of the DataTables.
749+
* @param sDom the dom
750+
* @returns {DTOptions} the options
751+
*/
752+
this.withDOM = function (sDom) {
753+
this.sDom = sDom;
754+
this.hasOverrideDom = true;
755+
return this;
756+
};
705757
// BOOTSTRAP INTEGRATION ---------
706758
// See http://getbootstrap.com
707759
/**
@@ -740,6 +792,7 @@
740792
this.withColReorder = function () {
741793
var colReorderPrefix = 'R';
742794
this.sDom = colReorderPrefix + fromNullable(this.sDom).or(DT_DEFAULT_DOM);
795+
this.hasColReorder = true;
743796
return this;
744797
};
745798
/**
@@ -788,6 +841,7 @@
788841
this.withColVis = function () {
789842
var colVisPrefix = 'C';
790843
this.sDom = colVisPrefix + fromNullable(this.sDom).or(DT_DEFAULT_DOM);
844+
this.hasColVis = true;
791845
return this;
792846
};
793847
/**
@@ -826,6 +880,7 @@
826880
this.withTableTools = function (sSwfPath) {
827881
var tableToolsPrefix = 'T';
828882
this.sDom = tableToolsPrefix + fromNullable(this.sDom).or(DT_DEFAULT_DOM);
883+
this.hasTableTools = true;
829884
if (angular.isString(sSwfPath)) {
830885
this.withTableToolsOption('sSwfPath', sSwfPath);
831886
}

0 commit comments

Comments
 (0)