diff --git a/README.md b/README.md
index 0205695de..e5deadaf9 100644
--- a/README.md
+++ b/README.md
@@ -59,15 +59,29 @@ Declare dependencies on your module app like this:
angular.module('myModule', ['datatables']);
```
+Usage
+-----
+
+See [github page](https://l-lin.github.io/angular-datatables).
+
Additional notes
----------------
-This module does not support multiple datatables in the same page YET!
+Each time a datatable is rendered, a message is sent to the parent scopes with the id of the table.
-Usage
------
+For instance, for the given dataTable:
-See [github page](https://l-lin.github.io/angular-datatables).
+```html
+
+```
+
+You can catch the event like this in your parent directive or controller:
+
+```js
+$scope.$on('event:dataTableLoaded', function(event, loadedDT) {
+ // loadedDT === {"id": "foobar"}
+});
+```
License
================
diff --git a/dist/angular-datatables.js b/dist/angular-datatables.js
index 7cb3c2159..e9663b80b 100644
--- a/dist/angular-datatables.js
+++ b/dist/angular-datatables.js
@@ -223,11 +223,16 @@
$elem.show();
$loading.hide();
};
- var _doRenderDataTable = function ($elem, options) {
+ var _renderDataTableAndEmitEvent = function ($elem, options, $scope) {
+ var oTable = $elem.DataTable(options);
+ $scope.$emit('event:dataTableLoaded', { id: $elem.attr('id') });
+ return oTable;
+ };
+ var _doRenderDataTable = function ($elem, options, $scope) {
// Add $timeout to be sure that angular has finished rendering before calling datatables
$timeout(function () {
_hideLoading($elem);
- $elem.DataTable(options);
+ _renderDataTableAndEmitEvent($elem, options, $scope);
}, 0, false);
};
/**
@@ -258,7 +263,7 @@
return {
options: options,
render: function ($scope, $elem) {
- _doRenderDataTable($elem, this.options);
+ _doRenderDataTable($elem, this.options, $scope);
}
};
};
@@ -274,7 +279,7 @@
render: function ($scope, $elem) {
var _this = this;
$scope.$on(DT_LAST_ROW_KEY, function () {
- _doRenderDataTable($elem, _this.options);
+ _doRenderDataTable($elem, _this.options, $scope);
});
}
};
@@ -287,7 +292,7 @@
*/
var PromiseRenderer = function (options) {
var oTable;
- var _render = function (options, $elem, data) {
+ var _render = function (options, $elem, data, $scope) {
options.aaData = data;
// Add $timeout to be sure that angular has finished rendering before calling datatables
$timeout(function () {
@@ -300,7 +305,7 @@
oTable.fnDraw();
oTable.fnAddData(options.aaData);
} else {
- oTable = $elem.DataTable(options);
+ oTable = _renderDataTableAndEmitEvent($elem, options, $scope);
}
}, 0, false);
};
@@ -310,7 +315,7 @@
var _this = this;
var _loadedPromise = null;
var _whenLoaded = function (data) {
- _render(_this.options, $elem, data);
+ _render(_this.options, $elem, data, $scope);
_loadedPromise = null;
};
var _startLoading = function (fnPromise) {
@@ -355,7 +360,7 @@
*/
var AjaxRenderer = function (options) {
var oTable;
- var _render = function (options, $elem) {
+ var _render = function (options, $elem, $scope) {
// Set it to true in order to be able to redraw the dataTable
options.bDestroy = true;
// Add $timeout to be sure that angular has finished rendering before calling datatables
@@ -374,7 +379,7 @@
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+)');
}
} else {
- oTable = $elem.DataTable(options);
+ oTable = _renderDataTableAndEmitEvent($elem, options, $scope);
}
}, 0, false);
};
@@ -392,12 +397,12 @@
$scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
_this.options.sAjaxSource = sAjaxSource;
_this.options.ajax = sAjaxSource;
- _render(options, $elem);
+ _render(options, $elem, $scope);
});
$scope.$watch('dtOptions.reload', function (reload) {
if (reload) {
$scope.dtOptions.reload = false;
- _render(options, $elem);
+ _render(options, $elem, $scope);
}
});
}
diff --git a/dist/angular-datatables.min.js b/dist/angular-datatables.min.js
index d39b308a1..f3d706049 100644
--- a/dist/angular-datatables.min.js
+++ b/dist/angular-datatables.min.js
@@ -2,4 +2,4 @@
* angular-datatables - v0.0.1
* https://github.com/l-lin/angular-datatables
*/
-!function(a,b,c,d){"use strict";d.module("datatable.bootstrap.tabletools",[]).service("$DTBootstrapTableTools",function(){var a=!1;this.integrate=function(){a||(c.fn.DataTable.TableTools&&(c.extend(!0,c.fn.DataTable.TableTools.classes,{container:"DTTT btn-group",buttons:{normal:"btn btn-default",disabled:"disabled"},collection:{container:"DTTT_dropdown dropdown-menu",buttons:{normal:"",disabled:"disabled"}},print:{info:"DTTT_print_info modal"},select:{row:"active"}}),c.extend(!0,c.fn.DataTable.TableTools.DEFAULTS.oTags,{collection:{container:"ul",button:"li",liner:"a"}})),a=!0)}}),d.module("datatables.bootstrap.colvis",[]).service("$DTBootstrapColVis",function(){var a=!1;this.integrate=function(b){a||(c.fn.DataTable.ColVis&&b(function(){c(".ColVis_MasterButton").addClass("btn btn-default"),c(".ColVis_Button").removeClass("ColVis_Button")}),a=!0)}}),d.module("datatables.bootstrap",["datatable.bootstrap.tabletools","datatables.bootstrap.colvis"]).service("$DTBootstrap",["$DTBootstrapTableTools","$DTBootstrapColVis",function(a,b){var e=!1,f=[],g=function(){c.extend(c.fn.dataTableExt.oStdClasses,{sWrapper:"dataTables_wrapper form-inline",sFilterInput:"form-control input-sm",sLengthSelect:"form-control input-sm",sFilter:"dataTables_filter",sLength:"dataTables_length"})},h=function(){c.fn.dataTableExt.oApi.fnPagingInfo=function(a){return{iStart:a._iDisplayStart,iEnd:a.fnDisplayEnd(),iLength:a._iDisplayLength,iTotal:a.fnRecordsTotal(),iFilteredTotal:a.fnRecordsDisplay(),iPage:-1===a._iDisplayLength?0:Math.ceil(a._iDisplayStart/a._iDisplayLength),iTotalPages:-1===a._iDisplayLength?0:Math.ceil(a.fnRecordsDisplay()/a._iDisplayLength)}}},i=function(){var a=function(a,b,d){var e=a.oLanguage.oPaginate,f=function(b){b.preventDefault(),a.oApi._fnPageChange(a,b.data.action)&&d(a)};c(b).append('");var g=c("a",b);c(g[0]).bind("click.DT",{action:"previous"},f),c(g[1]).bind("click.DT",{action:"next"},f)},b=function(a,b){var d,e,f,g,h,i,j=5,k=a.oInstance.fnPagingInfo(),l=a.aanFeatures.p,m=Math.floor(j/2);k.iTotalPages=k.iTotalPages-m?(h=k.iTotalPages-j+1,i=k.iTotalPages):(h=k.iPage-m+1,i=h+j-1);var n=function(d){d.preventDefault(),a._iDisplayStart=(parseInt(c("a",this).text(),10)-1)*k.iLength,b(a)};for(d=0,e=l.length;e>d;d++){for(c("li:gt(0)",l[d]).filter(":not(:last)").remove(),f=h;i>=f;f++)g=f===k.iPage+1?'class="active"':"",c("'+f+"").insertBefore(c("li:last",l[d])[0]).bind("click",n);0===k.iPage?c("li:first",l[d]).addClass("disabled"):c("li:first",l[d]).removeClass("disabled"),k.iPage===k.iTotalPages-1||0===k.iTotalPages?c("li:last",l[d]).addClass("disabled"):c("li:last",l[d]).removeClass("disabled")}};c.extend(c.fn.dataTableExt.oPagination,{bootstrap:{fnInit:a,fnUpdate:b}})},j=function(a){d.isFunction(a)&&f.push(a)},k=function(){e||(g(),h(),i(),j(function(){c("div.dataTables_filter").find("input").addClass("form-control"),c("div.dataTables_length").find("select").addClass("form-control")}),e=!0)};this.integrate=function(c){k(),a.integrate(),b.integrate(j),c.sDom="<'row'<'col-xs-6'l><'col-xs-6'f>r>t<'row'<'col-xs-6'i><'col-xs-6'p>>",c.sPaginationType="bootstrap",d.isUndefined(c.fnDrawCallback)&&(c.fnDrawCallback=function(){for(var a=0;aLoading..."),f=function(a){a.after(e),a.hide()},g=function(a){a.show(),e.hide()},h=function(a,b){c(function(){g(a),a.DataTable(b)},0,!1)},i={fromOptions:function(b,c){return c?new k(b):a.isDefined(b)?a.isDefined(b.fnPromise)&&null!==b.fnPromise?new l(b):a.isDefined(b.sAjaxSource)&&null!==b.sAjaxSource?new m(b):new j(b):new j}},j=function(a){return{options:a,render:function(a,b){h(b,this.options)}}},k=function(a){return{options:a,render:function(a,b){var c=this;a.$on(d,function(){h(b,c.options)})}}},l=function(b){var d,e=function(a,b,e){a.aaData=e,c(function(){g(b),a.bDestroy=!0,d?(d.fnClearTable(),d.fnDraw(),d.fnAddData(a.aaData)):d=b.DataTable(a)},0,!1)};return{options:b,render:function(b,c){var d=this,g=null,h=function(a){e(d.options,c,a),g=null},i=function(b){g=a.isFunction(b)?b():b,f(c),g.then(h)},j=function(a){g?g.then(function(){i(a)}):i(a)};b.$watch("dtOptions.fnPromise",function(b){if(!a.isDefined(b))throw new Error("You must provide a promise or a function that returns a promise!");j(b)}),b.$watch("dtOptions.reload",function(a){a&&(b.dtOptions.reload=!1,j(b.dtOptions.fnPromise))})}}},m=function(d){var e,f=function(b,d){b.bDestroy=!0,c(function(){if(g(d),e)if(a.isDefined(e.fnReloadAjax)&&a.isFunction(e.fnReloadAjax))e.fnReloadAjax(b.sAjaxSource);else{if(!a.isDefined(e.ajax)||!a.isFunction(e.ajax.load))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+)');e.ajax.url(b.sAjaxSource).load()}else e=d.DataTable(b)},0,!1)};return{options:d,render:function(c,e){var g=this;a.isUndefined(g.options.sAjaxDataProp)&&(g.options.sAjaxDataProp=b.sAjaxDataProp),a.isUndefined(g.options.aoColumns)&&(g.options.aoColumns=b.aoColumns),c.$watch("dtOptions.sAjaxSource",function(a){g.options.sAjaxSource=a,g.options.ajax=a,f(d,e)}),c.$watch("dtOptions.reload",function(a){a&&(c.dtOptions.reload=!1,f(d,e))})}}};return{restrict:"A",scope:{dtOptions:"=",dtColumns:"=",datatable:"@"},link:function(b,c){f(c);var d,e=b.datatable&&"ng"===b.datatable;a.isDefined(b.dtOptions)&&(d={},a.extend(d,b.dtOptions),a.isArray(b.dtColumns)&&(d.aoColumns=b.dtColumns)),i.fromOptions(d,e).render(b,c)}}}]).directive("dtRows",["$rootScope","DT_LAST_ROW_KEY",function(a,b){return{restrict:"A",link:function(c){c.$last===!0&&a.$broadcast(b)}}}])}(angular),function(a,b){"use strict";b.module("datatables.factory",["datatables.bootstrap"]).value("DT_DEFAULT_DOM","lfrtip").service("$DTDefaultOptions",function(){this.setLanguageSource=function(b){return a.extend(a.fn.dataTable.defaults,{oLanguage:{sUrl:b}}),this},this.setLanguage=function(b){return a.extend(!0,a.fn.dataTable.defaults,{oLanguage:b}),this},this.setDisplayLength=function(b){return a.extend(a.fn.dataTable.defaults,{iDisplayLength:b}),this}}).factory("DTOptionsBuilder",["$DTBootstrap","DT_DEFAULT_DOM",function(a,c){var d=function(d,e){this.sAjaxSource=d,this.fnPromise=e;var f=function(a){this.obj=a,this.isPresent=function(){return b.isDefined(this.obj)&&null!==this.obj},this.orEmptyObj=function(){return this.isPresent()?this.obj:{}},this.or=function(a){return this.isPresent()?this.obj:a}},g=function(a){return new f(a)};this.reloadData=function(){return this.reload=!0,this},this.withOption=function(a,c){return b.isString(a)&&(this[a]=c),this},this.withSource=function(a){return this.sAjaxSource=a,this},this.withDataProp=function(a){return this.sAjaxDataProp=a,this},this.withFnServerData=function(a){if(!b.isFunction(a))throw new Error("The parameter must be a function");return this.fnServerData=a,this},this.withPaginationType=function(a){if(!b.isString(a))throw new Error("The pagination type must be provided");return this.sPaginationType=a,this},this.withLanguage=function(a){return this.oLanguage=a,this},this.withLanguageSource=function(a){return this.withLanguage({sUrl:a})},this.withDisplayLength=function(a){return this.iDisplayLength=a,this},this.withFnPromise=function(a){return this.fnPromise=a,this},this.withBootstrap=function(){return a.integrate(this),this},this.withColReorderOption=function(a,c){return b.isString(a)&&(this.oColReorder=g(this.oColReorder).orEmptyObj(),this.oColReorder[a]=c),this},this.withColReorder=function(){var a="R";return this.sDom=a+g(this.sDom).or(c),this},this.withColReorderOrder=function(a){return b.isArray(a)&&this.withColReorderOption("aiOrder",a),this},this.withColReorderCallback=function(a){if(!b.isFunction(a))throw new Error("The reorder callback must be a function");return this.withColReorderOption("fnReorderCallback",a),this},this.withColVisOption=function(a,c){return b.isString(a)&&(this.oColVis=g(this.oColVis).orEmptyObj(),this.oColVis[a]=c),this},this.withColVis=function(){var a="C";return this.sDom=a+g(this.sDom).or(c),this},this.withColVisStateChange=function(a){if(!b.isFunction(a))throw new Error("The state change must be a function");return this.withColVisOption("fnStateChange",a),this},this.withTableToolsOption=function(a,c){return b.isString(a)&&(this.oTableTools=g(this.oTableTools).orEmptyObj(),this.oTableTools[a]=c),this},this.withTableTools=function(a){var d="T";return this.sDom=d+g(this.sDom).or(c),b.isString(a)&&this.withTableToolsOption("sSwfPath",a),this},this.withTableToolsButtons=function(a){return b.isArray(a)&&this.withTableToolsOption("aButtons",a),this}};return{newOptions:function(){return new d},fromSource:function(a){return new d(a,null)},fromFnPromise:function(a){return new d(null,a)}}}]).factory("DTColumnBuilder",function(){var a=function(a,c){if(b.isUndefined(a))throw new Error('The parameter "mData" is not defined!');this.mData=a,this.sTitle=c||"",this.withOption=function(a,c){return b.isString(a)&&(this[a]=c),this},this.withTitle=function(a){return this.sTitle=a,this},this.withClass=function(a){return this.sClass=a,this},this.notVisible=function(){return this.bVisible=!1,this},this.notSortable=function(){return this.bSortable=!1,this},this.renderWith=function(a){return this.mRender=a,this}};return{newColumn:function(b,c){return new a(b,c)}}})}(jQuery,angular),function(a){"use strict";a.module("datatables",["datatables.directive","datatables.factory","datatables.bootstrap"]).value("DT_LAST_ROW_KEY","datatable:lastRow")}(angular);
\ No newline at end of file
+!function(a,b,c,d){"use strict";d.module("datatable.bootstrap.tabletools",[]).service("$DTBootstrapTableTools",function(){var a=!1;this.integrate=function(){a||(c.fn.DataTable.TableTools&&(c.extend(!0,c.fn.DataTable.TableTools.classes,{container:"DTTT btn-group",buttons:{normal:"btn btn-default",disabled:"disabled"},collection:{container:"DTTT_dropdown dropdown-menu",buttons:{normal:"",disabled:"disabled"}},print:{info:"DTTT_print_info modal"},select:{row:"active"}}),c.extend(!0,c.fn.DataTable.TableTools.DEFAULTS.oTags,{collection:{container:"ul",button:"li",liner:"a"}})),a=!0)}}),d.module("datatables.bootstrap.colvis",[]).service("$DTBootstrapColVis",function(){var a=!1;this.integrate=function(b){a||(c.fn.DataTable.ColVis&&b(function(){c(".ColVis_MasterButton").addClass("btn btn-default"),c(".ColVis_Button").removeClass("ColVis_Button")}),a=!0)}}),d.module("datatables.bootstrap",["datatable.bootstrap.tabletools","datatables.bootstrap.colvis"]).service("$DTBootstrap",["$DTBootstrapTableTools","$DTBootstrapColVis",function(a,b){var e=!1,f=[],g=function(){c.extend(c.fn.dataTableExt.oStdClasses,{sWrapper:"dataTables_wrapper form-inline",sFilterInput:"form-control input-sm",sLengthSelect:"form-control input-sm",sFilter:"dataTables_filter",sLength:"dataTables_length"})},h=function(){c.fn.dataTableExt.oApi.fnPagingInfo=function(a){return{iStart:a._iDisplayStart,iEnd:a.fnDisplayEnd(),iLength:a._iDisplayLength,iTotal:a.fnRecordsTotal(),iFilteredTotal:a.fnRecordsDisplay(),iPage:-1===a._iDisplayLength?0:Math.ceil(a._iDisplayStart/a._iDisplayLength),iTotalPages:-1===a._iDisplayLength?0:Math.ceil(a.fnRecordsDisplay()/a._iDisplayLength)}}},i=function(){var a=function(a,b,d){var e=a.oLanguage.oPaginate,f=function(b){b.preventDefault(),a.oApi._fnPageChange(a,b.data.action)&&d(a)};c(b).append('");var g=c("a",b);c(g[0]).bind("click.DT",{action:"previous"},f),c(g[1]).bind("click.DT",{action:"next"},f)},b=function(a,b){var d,e,f,g,h,i,j=5,k=a.oInstance.fnPagingInfo(),l=a.aanFeatures.p,m=Math.floor(j/2);k.iTotalPages=k.iTotalPages-m?(h=k.iTotalPages-j+1,i=k.iTotalPages):(h=k.iPage-m+1,i=h+j-1);var n=function(d){d.preventDefault(),a._iDisplayStart=(parseInt(c("a",this).text(),10)-1)*k.iLength,b(a)};for(d=0,e=l.length;e>d;d++){for(c("li:gt(0)",l[d]).filter(":not(:last)").remove(),f=h;i>=f;f++)g=f===k.iPage+1?'class="active"':"",c("'+f+"").insertBefore(c("li:last",l[d])[0]).bind("click",n);0===k.iPage?c("li:first",l[d]).addClass("disabled"):c("li:first",l[d]).removeClass("disabled"),k.iPage===k.iTotalPages-1||0===k.iTotalPages?c("li:last",l[d]).addClass("disabled"):c("li:last",l[d]).removeClass("disabled")}};c.extend(c.fn.dataTableExt.oPagination,{bootstrap:{fnInit:a,fnUpdate:b}})},j=function(a){d.isFunction(a)&&f.push(a)},k=function(){e||(g(),h(),i(),j(function(){c("div.dataTables_filter").find("input").addClass("form-control"),c("div.dataTables_length").find("select").addClass("form-control")}),e=!0)};this.integrate=function(c){k(),a.integrate(),b.integrate(j),c.sDom="<'row'<'col-xs-6'l><'col-xs-6'f>r>t<'row'<'col-xs-6'i><'col-xs-6'p>>",c.sPaginationType="bootstrap",d.isUndefined(c.fnDrawCallback)&&(c.fnDrawCallback=function(){for(var a=0;aLoading..."),f=function(a){a.after(e),a.hide()},g=function(a){a.show(),e.hide()},h=function(a,b,c){var d=a.DataTable(b);return c.$emit("event:dataTableLoaded",{id:a.attr("id")}),d},i=function(a,b,d){c(function(){g(a),h(a,b,d)},0,!1)},j={fromOptions:function(b,c){return c?new l(b):a.isDefined(b)?a.isDefined(b.fnPromise)&&null!==b.fnPromise?new m(b):a.isDefined(b.sAjaxSource)&&null!==b.sAjaxSource?new n(b):new k(b):new k}},k=function(a){return{options:a,render:function(a,b){i(b,this.options,a)}}},l=function(a){return{options:a,render:function(a,b){var c=this;a.$on(d,function(){i(b,c.options,a)})}}},m=function(b){var d,e=function(a,b,e,f){a.aaData=e,c(function(){g(b),a.bDestroy=!0,d?(d.fnClearTable(),d.fnDraw(),d.fnAddData(a.aaData)):d=h(b,a,f)},0,!1)};return{options:b,render:function(b,c){var d=this,g=null,h=function(a){e(d.options,c,a,b),g=null},i=function(b){g=a.isFunction(b)?b():b,f(c),g.then(h)},j=function(a){g?g.then(function(){i(a)}):i(a)};b.$watch("dtOptions.fnPromise",function(b){if(!a.isDefined(b))throw new Error("You must provide a promise or a function that returns a promise!");j(b)}),b.$watch("dtOptions.reload",function(a){a&&(b.dtOptions.reload=!1,j(b.dtOptions.fnPromise))})}}},n=function(d){var e,f=function(b,d,f){b.bDestroy=!0,c(function(){if(g(d),e)if(a.isDefined(e.fnReloadAjax)&&a.isFunction(e.fnReloadAjax))e.fnReloadAjax(b.sAjaxSource);else{if(!a.isDefined(e.ajax)||!a.isFunction(e.ajax.load))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+)');e.ajax.url(b.sAjaxSource).load()}else e=h(d,b,f)},0,!1)};return{options:d,render:function(c,e){var g=this;a.isUndefined(g.options.sAjaxDataProp)&&(g.options.sAjaxDataProp=b.sAjaxDataProp),a.isUndefined(g.options.aoColumns)&&(g.options.aoColumns=b.aoColumns),c.$watch("dtOptions.sAjaxSource",function(a){g.options.sAjaxSource=a,g.options.ajax=a,f(d,e,c)}),c.$watch("dtOptions.reload",function(a){a&&(c.dtOptions.reload=!1,f(d,e,c))})}}};return{restrict:"A",scope:{dtOptions:"=",dtColumns:"=",datatable:"@"},link:function(b,c){f(c);var d,e=b.datatable&&"ng"===b.datatable;a.isDefined(b.dtOptions)&&(d={},a.extend(d,b.dtOptions),a.isArray(b.dtColumns)&&(d.aoColumns=b.dtColumns)),j.fromOptions(d,e).render(b,c)}}}]).directive("dtRows",["$rootScope","DT_LAST_ROW_KEY",function(a,b){return{restrict:"A",link:function(c){c.$last===!0&&a.$broadcast(b)}}}])}(angular),function(a,b){"use strict";b.module("datatables.factory",["datatables.bootstrap"]).value("DT_DEFAULT_DOM","lfrtip").service("$DTDefaultOptions",function(){this.setLanguageSource=function(b){return a.extend(a.fn.dataTable.defaults,{oLanguage:{sUrl:b}}),this},this.setLanguage=function(b){return a.extend(!0,a.fn.dataTable.defaults,{oLanguage:b}),this},this.setDisplayLength=function(b){return a.extend(a.fn.dataTable.defaults,{iDisplayLength:b}),this}}).factory("DTOptionsBuilder",["$DTBootstrap","DT_DEFAULT_DOM",function(a,c){var d=function(d,e){this.sAjaxSource=d,this.fnPromise=e;var f=function(a){this.obj=a,this.isPresent=function(){return b.isDefined(this.obj)&&null!==this.obj},this.orEmptyObj=function(){return this.isPresent()?this.obj:{}},this.or=function(a){return this.isPresent()?this.obj:a}},g=function(a){return new f(a)};this.reloadData=function(){return this.reload=!0,this},this.withOption=function(a,c){return b.isString(a)&&(this[a]=c),this},this.withSource=function(a){return this.sAjaxSource=a,this},this.withDataProp=function(a){return this.sAjaxDataProp=a,this},this.withFnServerData=function(a){if(!b.isFunction(a))throw new Error("The parameter must be a function");return this.fnServerData=a,this},this.withPaginationType=function(a){if(!b.isString(a))throw new Error("The pagination type must be provided");return this.sPaginationType=a,this},this.withLanguage=function(a){return this.oLanguage=a,this},this.withLanguageSource=function(a){return this.withLanguage({sUrl:a})},this.withDisplayLength=function(a){return this.iDisplayLength=a,this},this.withFnPromise=function(a){return this.fnPromise=a,this},this.withBootstrap=function(){return a.integrate(this),this},this.withColReorderOption=function(a,c){return b.isString(a)&&(this.oColReorder=g(this.oColReorder).orEmptyObj(),this.oColReorder[a]=c),this},this.withColReorder=function(){var a="R";return this.sDom=a+g(this.sDom).or(c),this},this.withColReorderOrder=function(a){return b.isArray(a)&&this.withColReorderOption("aiOrder",a),this},this.withColReorderCallback=function(a){if(!b.isFunction(a))throw new Error("The reorder callback must be a function");return this.withColReorderOption("fnReorderCallback",a),this},this.withColVisOption=function(a,c){return b.isString(a)&&(this.oColVis=g(this.oColVis).orEmptyObj(),this.oColVis[a]=c),this},this.withColVis=function(){var a="C";return this.sDom=a+g(this.sDom).or(c),this},this.withColVisStateChange=function(a){if(!b.isFunction(a))throw new Error("The state change must be a function");return this.withColVisOption("fnStateChange",a),this},this.withTableToolsOption=function(a,c){return b.isString(a)&&(this.oTableTools=g(this.oTableTools).orEmptyObj(),this.oTableTools[a]=c),this},this.withTableTools=function(a){var d="T";return this.sDom=d+g(this.sDom).or(c),b.isString(a)&&this.withTableToolsOption("sSwfPath",a),this},this.withTableToolsButtons=function(a){return b.isArray(a)&&this.withTableToolsOption("aButtons",a),this}};return{newOptions:function(){return new d},fromSource:function(a){return new d(a,null)},fromFnPromise:function(a){return new d(null,a)}}}]).factory("DTColumnBuilder",function(){var a=function(a,c){if(b.isUndefined(a))throw new Error('The parameter "mData" is not defined!');this.mData=a,this.sTitle=c||"",this.withOption=function(a,c){return b.isString(a)&&(this[a]=c),this},this.withTitle=function(a){return this.sTitle=a,this},this.withClass=function(a){return this.sClass=a,this},this.notVisible=function(){return this.bVisible=!1,this},this.notSortable=function(){return this.bSortable=!1,this},this.renderWith=function(a){return this.mRender=a,this}};return{newColumn:function(b,c){return new a(b,c)}}})}(jQuery,angular),function(a){"use strict";a.module("datatables",["datatables.directive","datatables.factory","datatables.bootstrap"]).value("DT_LAST_ROW_KEY","datatable:lastRow")}(angular);
\ No newline at end of file
diff --git a/src/angular-datatables.directive.js b/src/angular-datatables.directive.js
index c738be191..48026560f 100644
--- a/src/angular-datatables.directive.js
+++ b/src/angular-datatables.directive.js
@@ -16,11 +16,16 @@
$elem.show();
$loading.hide();
};
- var _doRenderDataTable = function($elem, options) {
+ var _renderDataTableAndEmitEvent = function ($elem, options, $scope) {
+ var oTable = $elem.DataTable(options);
+ $scope.$emit('event:dataTableLoaded', { id: $elem.attr('id') });
+ return oTable;
+ };
+ var _doRenderDataTable = function($elem, options, $scope) {
// Add $timeout to be sure that angular has finished rendering before calling datatables
$timeout(function() {
_hideLoading($elem);
- $elem.DataTable(options);
+ _renderDataTableAndEmitEvent($elem, options, $scope);
}, 0, false);
};
@@ -53,7 +58,7 @@
return {
options: options,
render: function ($scope, $elem) {
- _doRenderDataTable($elem, this.options);
+ _doRenderDataTable($elem, this.options, $scope);
}
};
};
@@ -70,7 +75,7 @@
render: function ($scope, $elem) {
var _this = this;
$scope.$on(DT_LAST_ROW_KEY, function () {
- _doRenderDataTable($elem, _this.options);
+ _doRenderDataTable($elem, _this.options, $scope);
});
}
};
@@ -84,7 +89,7 @@
*/
var PromiseRenderer = function(options) {
var oTable;
- var _render = function (options, $elem, data) {
+ var _render = function (options, $elem, data, $scope) {
options.aaData = data;
// Add $timeout to be sure that angular has finished rendering before calling datatables
$timeout(function () {
@@ -97,7 +102,7 @@
oTable.fnDraw();
oTable.fnAddData(options.aaData);
} else {
- oTable = $elem.DataTable(options);
+ oTable = _renderDataTableAndEmitEvent($elem, options, $scope);
}
}, 0, false);
};
@@ -107,7 +112,7 @@
var _this = this;
var _loadedPromise = null;
var _whenLoaded = function (data) {
- _render(_this.options, $elem, data);
+ _render(_this.options, $elem, data, $scope);
_loadedPromise = null;
};
var _startLoading = function (fnPromise) {
@@ -153,7 +158,7 @@
*/
var AjaxRenderer = function (options) {
var oTable;
- var _render = function (options, $elem) {
+ var _render = function (options, $elem, $scope) {
// Set it to true in order to be able to redraw the dataTable
options.bDestroy = true;
// Add $timeout to be sure that angular has finished rendering before calling datatables
@@ -172,7 +177,7 @@
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+)');
}
} else {
- oTable = $elem.DataTable(options);
+ oTable = _renderDataTableAndEmitEvent($elem, options, $scope);
}
}, 0, false);
};
@@ -190,12 +195,12 @@
$scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
_this.options.sAjaxSource = sAjaxSource;
_this.options.ajax = sAjaxSource;
- _render(options, $elem);
+ _render(options, $elem, $scope);
});
$scope.$watch('dtOptions.reload', function (reload) {
if (reload) {
$scope.dtOptions.reload = false;
- _render(options, $elem);
+ _render(options, $elem, $scope);
}
});
}