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

Commit 60b14cb

Browse files
committed
Merge branch 'VanDalkvist-dev' into dev
2 parents c3f21cb + f1e5038 commit 60b14cb

File tree

4 files changed

+51
-27
lines changed

4 files changed

+51
-27
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,29 @@ Declare dependencies on your module app like this:
5959
angular.module('myModule', ['datatables']);
6060
```
6161

62+
Usage
63+
-----
64+
65+
See [github page](https://l-lin.github.io/angular-datatables).
66+
6267
Additional notes
6368
----------------
6469

65-
This module does not support multiple datatables in the same page YET!
70+
Each time a datatable is rendered, a message is sent to the parent scopes with the id of the table.
6671

67-
Usage
68-
-----
72+
For instance, for the given dataTable:
6973

70-
See [github page](https://l-lin.github.io/angular-datatables).
74+
```html
75+
<table id="foobar" datatable dt-options="dtOptions" dt-columns="dtColumns"></table>
76+
```
77+
78+
You can catch the event like this in your parent directive or controller:
79+
80+
```js
81+
$scope.$on('event:dataTableLoaded', function(event, loadedDT) {
82+
// loadedDT === {"id": "foobar"}
83+
});
84+
```
7185

7286
License
7387
================

dist/angular-datatables.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,16 @@
223223
$elem.show();
224224
$loading.hide();
225225
};
226-
var _doRenderDataTable = function ($elem, options) {
226+
var _renderDataTableAndEmitEvent = function ($elem, options, $scope) {
227+
var oTable = $elem.DataTable(options);
228+
$scope.$emit('event:dataTableLoaded', { id: $elem.attr('id') });
229+
return oTable;
230+
};
231+
var _doRenderDataTable = function ($elem, options, $scope) {
227232
// Add $timeout to be sure that angular has finished rendering before calling datatables
228233
$timeout(function () {
229234
_hideLoading($elem);
230-
$elem.DataTable(options);
235+
_renderDataTableAndEmitEvent($elem, options, $scope);
231236
}, 0, false);
232237
};
233238
/**
@@ -258,7 +263,7 @@
258263
return {
259264
options: options,
260265
render: function ($scope, $elem) {
261-
_doRenderDataTable($elem, this.options);
266+
_doRenderDataTable($elem, this.options, $scope);
262267
}
263268
};
264269
};
@@ -274,7 +279,7 @@
274279
render: function ($scope, $elem) {
275280
var _this = this;
276281
$scope.$on(DT_LAST_ROW_KEY, function () {
277-
_doRenderDataTable($elem, _this.options);
282+
_doRenderDataTable($elem, _this.options, $scope);
278283
});
279284
}
280285
};
@@ -287,7 +292,7 @@
287292
*/
288293
var PromiseRenderer = function (options) {
289294
var oTable;
290-
var _render = function (options, $elem, data) {
295+
var _render = function (options, $elem, data, $scope) {
291296
options.aaData = data;
292297
// Add $timeout to be sure that angular has finished rendering before calling datatables
293298
$timeout(function () {
@@ -300,7 +305,7 @@
300305
oTable.fnDraw();
301306
oTable.fnAddData(options.aaData);
302307
} else {
303-
oTable = $elem.DataTable(options);
308+
oTable = _renderDataTableAndEmitEvent($elem, options, $scope);
304309
}
305310
}, 0, false);
306311
};
@@ -310,7 +315,7 @@
310315
var _this = this;
311316
var _loadedPromise = null;
312317
var _whenLoaded = function (data) {
313-
_render(_this.options, $elem, data);
318+
_render(_this.options, $elem, data, $scope);
314319
_loadedPromise = null;
315320
};
316321
var _startLoading = function (fnPromise) {
@@ -355,7 +360,7 @@
355360
*/
356361
var AjaxRenderer = function (options) {
357362
var oTable;
358-
var _render = function (options, $elem) {
363+
var _render = function (options, $elem, $scope) {
359364
// Set it to true in order to be able to redraw the dataTable
360365
options.bDestroy = true;
361366
// Add $timeout to be sure that angular has finished rendering before calling datatables
@@ -374,7 +379,7 @@
374379
throw new Error('Reload Ajax not supported. Please use the plugin "fnReloadAjax" (https://next.datatables.net/plug-ins/api/fnReloadAjax) or use a more recent version of DataTables (v1.10+)');
375380
}
376381
} else {
377-
oTable = $elem.DataTable(options);
382+
oTable = _renderDataTableAndEmitEvent($elem, options, $scope);
378383
}
379384
}, 0, false);
380385
};
@@ -392,12 +397,12 @@
392397
$scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
393398
_this.options.sAjaxSource = sAjaxSource;
394399
_this.options.ajax = sAjaxSource;
395-
_render(options, $elem);
400+
_render(options, $elem, $scope);
396401
});
397402
$scope.$watch('dtOptions.reload', function (reload) {
398403
if (reload) {
399404
$scope.dtOptions.reload = false;
400-
_render(options, $elem);
405+
_render(options, $elem, $scope);
401406
}
402407
});
403408
}

0 commit comments

Comments
 (0)