|
10 | 10 | (function (window, document, $, angular) {
|
11 | 11 | 'use strict';
|
12 | 12 | 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 | + }; |
14 | 22 | this.integrate = function () {
|
15 | 23 | if (!_initializedTableTools) {
|
| 24 | + _saveFnToBeOverrided(); |
16 | 25 | /*
|
17 | 26 | * TableTools Bootstrap compatibility
|
18 | 27 | * Required TableTools 2.1+
|
|
47 | 56 | _initializedTableTools = true;
|
48 | 57 | }
|
49 | 58 | };
|
| 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 | + }; |
50 | 66 | });
|
51 | 67 | angular.module('datatables.bootstrap.colvis', []).service('$DTBootstrapColVis', function () {
|
52 | 68 | var _initializedColVis = false;
|
|
69 | 85 | angular.module('datatables.bootstrap', [
|
70 | 86 | 'datatable.bootstrap.tabletools',
|
71 | 87 | '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', [ |
73 | 89 | '$DTBootstrapTableTools',
|
74 | 90 | '$DTBootstrapColVis',
|
75 |
| - function ($DTBootstrapTableTools, $DTBootstrapColVis) { |
| 91 | + 'DT_BOOTSTRAP_DEFAULT_DOM', |
| 92 | + function ($DTBootstrapTableTools, $DTBootstrapColVis, DT_BOOTSTRAP_DEFAULT_DOM) { |
76 | 93 | var _initialized = false, _drawCallbackFunctionList = [], _savedFn = {};
|
77 | 94 | var _saveFnToBeOverrided = function () {
|
78 | 95 | _savedFn.oStdClasses = angular.copy($.fn.dataTableExt.oStdClasses);
|
79 | 96 | _savedFn.fnPagingInfo = $.fn.dataTableExt.oApi.fnPagingInfo;
|
80 | 97 | _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 | + } |
81 | 104 | }, _revertToDTFn = function () {
|
82 | 105 | $.extend($.fn.dataTableExt.oStdClasses, _savedFn.oStdClasses);
|
83 | 106 | $.fn.dataTableExt.oApi.fnPagingInfo = _savedFn.fnPagingInfo;
|
|
223 | 246 | }
|
224 | 247 | };
|
225 | 248 | 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 | + }; |
238 | 276 | /**
|
239 | 277 | * Integrate Bootstrap
|
240 | 278 | * @param options the datatables options
|
|
243 | 281 | _init();
|
244 | 282 | $DTBootstrapTableTools.integrate();
|
245 | 283 | $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); |
248 | 285 | if (angular.isUndefined(options.fnDrawCallback)) {
|
249 | 286 | // Call every drawcallback functions
|
250 | 287 | options.fnDrawCallback = function () {
|
|
257 | 294 | this.deIntegrate = function () {
|
258 | 295 | if (_initialized) {
|
259 | 296 | _revertToDTFn();
|
| 297 | + $DTBootstrapTableTools.deIntegrate(); |
260 | 298 | _initialized = false;
|
261 | 299 | }
|
262 | 300 | };
|
|
565 | 603 | this.sAjaxSource = sAjaxSource;
|
566 | 604 | this.fnPromise = fnPromise;
|
567 | 605 | this.integrateBootstrap = false;
|
| 606 | + this.hasColVis = false; |
| 607 | + this.hasColReorder = false; |
| 608 | + this.hasTableTools = false; |
| 609 | + this.hasOverrideDom = false; |
568 | 610 | /**
|
569 | 611 | * Optional class to handle undefined or null
|
570 | 612 | * @param obj the object to wrap
|
|
702 | 744 | this.fnPromise = fnPromise;
|
703 | 745 | return this;
|
704 | 746 | };
|
| 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 | + }; |
705 | 757 | // BOOTSTRAP INTEGRATION ---------
|
706 | 758 | // See http://getbootstrap.com
|
707 | 759 | /**
|
|
740 | 792 | this.withColReorder = function () {
|
741 | 793 | var colReorderPrefix = 'R';
|
742 | 794 | this.sDom = colReorderPrefix + fromNullable(this.sDom).or(DT_DEFAULT_DOM);
|
| 795 | + this.hasColReorder = true; |
743 | 796 | return this;
|
744 | 797 | };
|
745 | 798 | /**
|
|
788 | 841 | this.withColVis = function () {
|
789 | 842 | var colVisPrefix = 'C';
|
790 | 843 | this.sDom = colVisPrefix + fromNullable(this.sDom).or(DT_DEFAULT_DOM);
|
| 844 | + this.hasColVis = true; |
791 | 845 | return this;
|
792 | 846 | };
|
793 | 847 | /**
|
|
826 | 880 | this.withTableTools = function (sSwfPath) {
|
827 | 881 | var tableToolsPrefix = 'T';
|
828 | 882 | this.sDom = tableToolsPrefix + fromNullable(this.sDom).or(DT_DEFAULT_DOM);
|
| 883 | + this.hasTableTools = true; |
829 | 884 | if (angular.isString(sSwfPath)) {
|
830 | 885 | this.withTableToolsOption('sSwfPath', sSwfPath);
|
831 | 886 | }
|
|
0 commit comments