{"action":"opened","issue":{"url":"https://api.github.com/repos/l-lin/angular-datatables/issues/307","labels_url":"https://api.github.com/repos/l-lin/angular-datatables/issues/307/labels{/name}","comments_url":"https://api.github.com/repos/l-lin/angular-datatables/issues/307/comments","events_url":"https://api.github.com/repos/l-lin/angular-datatables/issues/307/events","html_url":"https://github.com/l-lin/angular-datatables/issues/307","id":74402430,"number":307,"title":"Add the possibility to provide an object or a callback function to fetch the DT instance","user":{"login":"l-lin","id":5452304,"avatar_url":"https://avatars.githubusercontent.com/u/5452304?v=3","gravatar_id":"","url":"https://api.github.com/users/l-lin","html_url":"https://github.com/l-lin","followers_url":"https://api.github.com/users/l-lin/followers","following_url":"https://api.github.com/users/l-lin/following{/other_user}","gists_url":"https://api.github.com/users/l-lin/gists{/gist_id}","starred_url":"https://api.github.com/users/l-lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l-lin/subscriptions","organizations_url":"https://api.github.com/users/l-lin/orgs","repos_url":"https://api.github.com/users/l-lin/repos","events_url":"https://api.github.com/users/l-lin/events{/privacy}","received_events_url":"https://api.github.com/users/l-lin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/l-lin/angular-datatables/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/l-lin/angular-datatables/milestones/8","html_url":"https://github.com/l-lin/angular-datatables/milestones/v0.4.3","labels_url":"https://api.github.com/repos/l-lin/angular-datatables/milestones/8/labels","id":1046752,"number":8,"title":"v0.4.3","description":"","creator":{"login":"l-lin","id":5452304,"avatar_url":"https://avatars.githubusercontent.com/u/5452304?v=3","gravatar_id":"","url":"https://api.github.com/users/l-lin","html_url":"https://github.com/l-lin","followers_url":"https://api.github.com/users/l-lin/followers","following_url":"https://api.github.com/users/l-lin/following{/other_user}","gists_url":"https://api.github.com/users/l-lin/gists{/gist_id}","starred_url":"https://api.github.com/users/l-lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l-lin/subscriptions","organizations_url":"https://api.github.com/users/l-lin/orgs","repos_url":"https://api.github.com/users/l-lin/repos","events_url":"https://api.github.com/users/l-lin/events{/privacy}","received_events_url":"https://api.github.com/users/l-lin/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":7,"state":"open","created_at":"2015-03-31T12:03:57Z","updated_at":"2015-05-08T15:32:55Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2015-05-08T15:32:55Z","updated_at":"2015-05-08T15:32:55Z","closed_at":null,"body":"Instead of using `DTInstances` service (which caused more headaches than expected :disappointed: ), one [solution](https://github.com/l-lin/angular-datatables/issues/284#issuecomment-95991003) 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.\r\nOn example:\r\n```html\r\n<div ng-controller=\"ShowCaseCtrl as showCase\">\r\n    <table datatable\r\n           dt-options=\"showCase.dtOptions\"\r\n           dt-instance=\"showCase.dtInstance\">\r\n    </table>\r\n</div>\r\n```\r\n```js\r\nangular.controller('ShowCaseCtrl ', ShowCaseCtrl );\r\nfunction ShowCaseCtrl(DTOptionsBuilder) {\r\n    var vm = this;\r\n    vm.dtInstance = {}; // This will be set automatically with the two-way data binding\r\n    vm.dtOptions = DTOptionsBuilder.fromSource('data.json');\r\n}\r\n```\r\n\r\nThe user should also have the possibility to set a callback function instead of a variable:\r\n```html\r\n<div ng-controller=\"ShowCaseCtrl as showCase\">\r\n    <table datatable\r\n           dt-options=\"showCase.dtOptions\" \r\n           dt-instance=\"showCase.dtInstanceCallback\">\r\n    </table>\r\n</div>\r\n```\r\n```js\r\nangular.controller('ShowCaseCtrl ', ShowCaseCtrl );\r\nfunction ShowCaseCtrl(DTOptionsBuilder) {\r\n    var vm = this;\r\n    vm.dtInstances = [];\r\n    vm.dtOptions = DTOptionsBuilder.fromSource('data.json');\r\n    vm.dtInstanceCallback = dtInstanceCallback;\r\n\r\n    function dtInstanceCallback(dtInstance) {\r\n        vm.dtInstances.push(dtInstance);\r\n    }\r\n}\r\n```\r\n\r\n**Note**: This enhancement will completely replace the `DTInstances` service. So expect the removal of the `DTInstances` service in the v0.5.0+ versions!!!"}}