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

Commit 7e515f1

Browse files
committed
Merge branch 'matthew-sycle-dev' into dev
2 parents ecba70d + 63c049d commit 7e515f1

10 files changed

+69
-35
lines changed

demo/app.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ angular.module('showcase', [
4343
.config(sampleConfig)
4444
.config(routerConfig)
4545
.config(translateConfig)
46-
.factory('DTLoadingTemplate', dtLoadingTemplate);
46+
.run(initDT);
4747

4848
backToTop.init({
4949
theme: 'classic', // Available themes: 'classic', 'sky', 'slate'
@@ -110,8 +110,6 @@ function translateConfig($translateProvider) {
110110
$translateProvider.preferredLanguage('en');
111111
}
112112

113-
function dtLoadingTemplate() {
114-
return {
115-
html: '<img src="/angular-datatables/images/loading.gif" />'
116-
};
113+
function initDT(DTDefaultOptions) {
114+
DTDefaultOptions.setLoadingTemplate('<img src="/angular-datatables/images/loading.gif" />');
117115
}

demo/basic/angularWayWithOptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
angular.module('showcase.angularWay.withOptions', ['datatables', 'ngResource'])
33
.controller('AngularWayWithOptionsCtrl', AngularWayWithOptionsCtrl);
44

5-
function AngularWayWithOptionsCtrl($resource, DTOptionsBuilder, DTColumnDefBuilder) {
5+
function AngularWayWithOptionsCtrl($scope, $resource, DTOptionsBuilder, DTColumnDefBuilder) {
66
var vm = this;
77
vm.persons = [];
88
vm.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers').withDisplayLength(2);

demo/basic/overrideLoadingTpl.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h1><i class="fa fa-play"></i>&nbsp;Override <code>Loading</code> template</h1>
1010
<li>
1111
One comes from this module. It is displayed before the table is rendered. This loading has been added because
1212
angular-datables offers the possibility to fetch the data and options with promises. So before rendering the
13-
table, the promises need to be resoved, thus adding a loading message to let users know that something is
13+
table, the promises need to be resolved, thus adding a loading message to let users know that something is
1414
processing.
1515
</li>
1616
<li>
@@ -22,17 +22,20 @@ <h1><i class="fa fa-play"></i>&nbsp;Override <code>Loading</code> template</h1>
2222
When loading data, the angular module will display by default <code>&lt;h3 class="dt-loading"&gt;Loading...&lt;/h3&gt;</code>.
2323
</p>
2424
<p>
25-
You can make your own custom loading html by override the <code>DTLoadingTemplate</code> like this:
25+
You can make your own custom loading html by calling the method <code>DTDefaultOptions.setLoadingTemplate()</code> like this:
2626
</p>
27+
<div class="alert alert-info">
28+
<p>
29+
Angular-datatables is using the angular service <code>$compile</code>. So you can use angular directives if you want.
30+
</p>
31+
</div>
2732
</section>
2833
<section class="showcase no-tab">
2934
<div hljs>
3035
angular.module('showcase', ['datatables']).
31-
factory('DTLoadingTemplate', dtLoadingTemplate);
32-
function dtLoadingTemplate() {
33-
return {
34-
html: '<img src="images/loading.gif" />'
35-
};
36+
run(initDT);
37+
function initDT(DTDefaultOptions) {
38+
DTDefaultOptions.setLoadingTemplate('<img src="images/loading.gif" />');
3639
}
3740
</div>
3841
</section>

dist/angular-datatables.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function dataTable($q, $http, DTRendererFactory, DTRendererService, DTPropertyUt
4747
angular.forEach(['dtColumns', 'dtColumnDefs', 'dtOptions'], function(tableDefField) {
4848
$scope[watchFunction].call($scope, tableDefField, handleChanges, true);
4949
});
50-
DTRendererService.showLoading($elem);
50+
DTRendererService.showLoading($elem, $scope);
5151
ctrl.render($elem, ctrl.buildOptionsPromise(), _staticHTML);
5252
};
5353
}
@@ -411,11 +411,14 @@ function dtColumnDefBuilder(DTColumnBuilder) {
411411
}
412412
dtColumnDefBuilder.$inject = ['DTColumnBuilder'];
413413

414-
function dtLoadingTemplate() {
414+
function dtLoadingTemplate($compile, DTDefaultOptions) {
415415
return {
416-
html: '<h3 class="dt-loading">Loading...</h3>'
416+
compileHtml: function($scope) {
417+
return $compile(angular.element(DTDefaultOptions.loadingTemplate))($scope);
418+
}
417419
};
418420
}
421+
dtLoadingTemplate.$inject = ['$compile', 'DTDefaultOptions'];
419422

420423
'use strict';
421424

@@ -600,7 +603,9 @@ angular.module('datatables.options', [])
600603

601604
function dtDefaultOptions() {
602605
var options = {
606+
loadingTemplate: '<h3 class="dt-loading">Loading...</h3>',
603607
bootstrapOptions: {},
608+
setLoadingTemplate: setLoadingTemplate,
604609
setLanguageSource: setLanguageSource,
605610
setLanguage: setLanguage,
606611
setDisplayLength: setDisplayLength,
@@ -609,6 +614,16 @@ function dtDefaultOptions() {
609614

610615
return options;
611616

617+
/**
618+
* Set the default loading template
619+
* @param loadingTemplate the HTML to display when loading the table
620+
* @returns {DTDefaultOptions} the default option config
621+
*/
622+
function setLoadingTemplate(loadingTemplate) {
623+
options.loadingTemplate = loadingTemplate;
624+
return options;
625+
}
626+
612627
/**
613628
* Set the default language source for all datatables
614629
* @param sLanguageSource the language source
@@ -690,8 +705,8 @@ function dtRendererService(DTLoadingTemplate) {
690705
};
691706
return rendererService;
692707

693-
function showLoading($elem) {
694-
var $loading = angular.element(DTLoadingTemplate.html);
708+
function showLoading($elem, $scope) {
709+
var $loading = angular.element(DTLoadingTemplate.compileHtml($scope));
695710
$elem.after($loading);
696711
$elem.hide();
697712
$loading.show();
@@ -767,6 +782,7 @@ function dtDefaultRenderer($q, DTRenderer, DTRendererService, DTInstanceFactory)
767782
function create(options) {
768783
var _oTable;
769784
var _$elem;
785+
var _$scope;
770786
var renderer = Object.create(DTRenderer);
771787
renderer.name = 'DTDefaultRenderer';
772788
renderer.options = options;
@@ -775,8 +791,9 @@ function dtDefaultRenderer($q, DTRenderer, DTRendererService, DTInstanceFactory)
775791
renderer.changeData = changeData;
776792
renderer.rerender = rerender;
777793

778-
function render($elem) {
794+
function render($elem, $scope) {
779795
_$elem = $elem;
796+
_$scope = $scope;
780797
var dtInstance = DTInstanceFactory.newDTInstance(renderer);
781798
var result = DTRendererService.hideLoadingAndRenderDataTable($elem, renderer.options);
782799
_oTable = result.DataTable;
@@ -794,7 +811,7 @@ function dtDefaultRenderer($q, DTRenderer, DTRendererService, DTInstanceFactory)
794811

795812
function rerender() {
796813
_oTable.destroy();
797-
DTRendererService.showLoading(_$elem);
814+
DTRendererService.showLoading(_$elem, _$scope);
798815
render(_$elem);
799816
}
800817
return renderer;
@@ -874,7 +891,7 @@ function dtNGRenderer($log, $q, $compile, $timeout, DTRenderer, DTRendererServic
874891

875892
function rerender() {
876893
_destroyAndCompile();
877-
DTRendererService.showLoading(_$elem);
894+
DTRendererService.showLoading(_$elem, _parentScope);
878895
$timeout(function() {
879896
var result = DTRendererService.hideLoadingAndRenderDataTable(_$elem, renderer.options);
880897
_oTable = result.DataTable;
@@ -963,7 +980,7 @@ function dtPromiseRenderer($q, $timeout, $log, DTRenderer, DTRendererService, DT
963980

964981
function rerender() {
965982
_oTable.destroy();
966-
DTRendererService.showLoading(_$elem);
983+
DTRendererService.showLoading(_$elem, _$scope);
967984
render(_$elem, _$scope);
968985
}
969986

@@ -1105,7 +1122,7 @@ function dtAjaxRenderer($q, $timeout, DTRenderer, DTRendererService, DT_DEFAULT_
11051122
options.bDestroy = true;
11061123
if (_oTable) {
11071124
_oTable.destroy();
1108-
DTRendererService.showLoading(_$elem);
1125+
DTRendererService.showLoading(_$elem, _$scope);
11091126
// Empty in case of columns change
11101127
$elem.empty();
11111128
}

0 commit comments

Comments
 (0)