Skip to content

Commit 9e68cbd

Browse files
committed
The Angular way! yeah
1 parent c9c342f commit 9e68cbd

File tree

5 files changed

+25
-43
lines changed

5 files changed

+25
-43
lines changed

dist/angular-datatables.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@
214214
'DT_DEFAULT_OPTIONS',
215215
'$timeout',
216216
'DT_LAST_ROW_KEY',
217-
'DT_HAS_NG_ROWS',
218-
function ($http, DT_DEFAULT_OPTIONS, $timeout, DT_LAST_ROW_KEY, DT_HAS_NG_ROWS) {
219-
var hasNgRows = false;
217+
function ($http, DT_DEFAULT_OPTIONS, $timeout, DT_LAST_ROW_KEY) {
220218
var $loading = angular.element('<h3>Loading...</h3>');
221219
var _doRenderDataTable = function ($elem, options) {
222220
// Add $timeout to be sure that angular has finished rendering before calling datatables
@@ -227,20 +225,17 @@
227225
$elem.dataTable(options);
228226
}, 0, false);
229227
};
230-
var _renderDataTableIfNoNgRows = function ($elem, options) {
231-
// Mmh ugly... I don't know how to do it in another way...
232-
// Waiting in case we have ng rows
233-
$timeout(function () {
234-
if (!hasNgRows) {
235-
_doRenderDataTable($elem, options);
236-
}
237-
}, 100);
228+
var _renderDataTableIfNoNgRows = function ($elem, options, isNgDisplay) {
229+
if (!isNgDisplay) {
230+
_doRenderDataTable($elem, options);
231+
}
238232
};
239233
return {
240234
restrict: 'A',
241235
scope: {
242236
dtOptions: '=',
243-
dtColumns: '='
237+
dtColumns: '=',
238+
datatable: '@'
244239
},
245240
link: function ($scope, $elem) {
246241
// Display loading
@@ -268,10 +263,8 @@
268263
}
269264
}
270265
}
271-
_renderDataTableIfNoNgRows($elem, options);
272-
$scope.$on(DT_HAS_NG_ROWS, function () {
273-
hasNgRows = true;
274-
});
266+
var isNgDisplay = $scope.datatable && $scope.datatable === 'ng';
267+
_renderDataTableIfNoNgRows($elem, options, isNgDisplay);
275268
$scope.$on(DT_LAST_ROW_KEY, function () {
276269
_doRenderDataTable($elem, options);
277270
});
@@ -281,12 +274,10 @@
281274
]).directive('dtRows', [
282275
'$rootScope',
283276
'DT_LAST_ROW_KEY',
284-
'DT_HAS_NG_ROWS',
285-
function ($rootScope, DT_LAST_ROW_KEY, DT_HAS_NG_ROWS) {
277+
function ($rootScope, DT_LAST_ROW_KEY) {
286278
return {
287279
restrict: 'A',
288280
link: function ($scope) {
289-
$rootScope.$broadcast(DT_HAS_NG_ROWS);
290281
if ($scope.$last === true) {
291282
$rootScope.$broadcast(DT_LAST_ROW_KEY);
292283
}
@@ -486,7 +477,7 @@
486477
* Add option to "oColReorder" option
487478
* @param key the key of the option to add
488479
* @param value an object or a function of the function
489-
* @param {DTOption} the options
480+
* @return {DTOptions} the options
490481
*/
491482
this.withColReorderOption = function (key, value) {
492483
if (angular.isString(key)) {
@@ -698,5 +689,5 @@
698689
'datatables.directive',
699690
'datatables.factory',
700691
'datatables.bootstrap'
701-
]).value('DT_LAST_ROW_KEY', 'datatable:lastRow').value('DT_HAS_NG_ROWS', 'datatable:hasNgRow');
692+
]).value('DT_LAST_ROW_KEY', 'datatable:lastRow');
702693
}(angular));

dist/angular-datatables.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)