Add the possibility to provide an object or a callback function to fetch the DT instance
See original GitHub issueInstead of using DTInstances service (which caused more headaches than expected 😞 ), one solution is to create another directive dt-instance in which it will be possible to provide a variable that angular-datatables will populate with the DT directive instance.
One example:
<div ng-controller="ShowCaseCtrl as showCase">
<table datatable
dt-options="showCase.dtOptions"
dt-instance="showCase.dtInstance">
</table>
</div>
angular.controller('ShowCaseCtrl ', ShowCaseCtrl );
function ShowCaseCtrl(DTOptionsBuilder) {
var vm = this;
vm.dtInstance = {}; // This will be set automatically with the two-way data binding
vm.dtOptions = DTOptionsBuilder.fromSource('data.json');
}
The user should also have the possibility to set a callback function instead of a variable:
<div ng-controller="ShowCaseCtrl as showCase">
<table datatable
dt-options="showCase.dtOptions"
dt-instance="showCase.dtInstanceCallback">
</table>
</div>
angular.controller('ShowCaseCtrl ', ShowCaseCtrl );
function ShowCaseCtrl(DTOptionsBuilder) {
var vm = this;
vm.dtInstances = [];
vm.dtOptions = DTOptionsBuilder.fromSource('data.json');
vm.dtInstanceCallback = dtInstanceCallback;
function dtInstanceCallback(dtInstance) {
vm.dtInstances.push(dtInstance);
}
}
Note: This enhancement will completely replace the DTInstances service. So expect the removal of the DTInstances service in the v0.5.0+ versions!!!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:7 (1 by maintainers)

I followed lin’s code and trying to use
vm.dtInstace.reloadData()I’ve got this warning and the data is not reloaded.
The Angular Renderer does not support reloading data. You need to do it directly on your model