DTInstances
A DataTable directive instance is created each time a DataTable is rendered. You can fetch it by calling the service
DTInstances.getLast() to fetch the last instance or DTInstance.getList() to fetch the entire list of instances.
| Helper/Wrapper | API | Description |
|---|---|---|
DTInstances |
getLast() |
Returns a promise that fetches the last datatable instance that was rendered.
angular.module('myModule', ['datatables']).controller('MyCtrl', MyCtrl);
function MyCtrl(DTInstances) {
DTInstances.getLast().then(function(lastDTInstance) {
// lastDTInstance === {
// "id": "foobar2",
// "DataTable": oTable,
// "dataTable": $oTable,
// "reloadData": fnReloadData,
// "changeData": fnChangeData,
// "rerender": fnRerender
// }
// loadedDT.DataTable is the DataTable API instance
// loadedDT.dataTable is the jQuery Object
// See http://datatables.net/manual/api#Accessing-the-API
});
}
|
DTInstances |
getList() |
Returns a promise that fetches all the datatables instances that were rendered.
angular.module('myModule', ['datatables']).controller('MyCtrl', MyCtrl);
function MyCtrl(DTInstances) {
DTInstances.getList().then(function(dtInstances) {
// dtInstances === {
// "foobar": {
// "id": "foobar2",
// "DataTable": oTable,
// "dataTable": $oTable,
// "reloadData": fnReloadData,
// "changeData": fnChangeData,
// "rerender": fnRerender
// },
// "foobar2": {
// "id": "foobar2",
// "DataTable": oTable,
// "dataTable": $oTable,
// "reloadData": fnReloadData,
// "changeData": fnChangeData,
// "rerender": fnRerender
// }
// }
});
}
|
DTInstance |
reloadData() |
Reload the data of the DataTable. This API is only available for the Ajax Renderer and Promise Renderer!
angular.module('myModule', ['datatables']).controller('MyCtrl', MyCtrl);
function MyCtrl(DTInstances) {
DTInstances.getLast().then(function(dtInstance) {
dtInstance.reloadData();
});
}
|
DTInstance |
changeData(data)
Depending of the using renderer, you will need to provide:
|
Change the data of the DataTable. This API is only available for the Ajax Renderer and Promise Renderer!
angular.module('myModule', ['datatables']).controller('MyCtrl', MyCtrl);
function MyCtrl($resource, DTInstances) {
DTInstances.getLast().then(function(dtInstance) {
// For Ajax renderers
dtInstance.changeData('data.json');
// For Promise renderers
dtInstance.changeData(function() {
return $resource('data.json').query().$promise;
});
});
}
|
DTInstance |
rerender()
|
This method will call the renderer to re-render the table again This is not the same as DataTable's draw(); API. It will completely remove the table, then it will re-render the table, resending the request to the server if necessarily.
angular.module('myModule', ['datatables']).controller('MyCtrl', MyCtrl);
function MyCtrl(DTOptionsBuilder, DTColumnDefBuilder, DTInstances) {
DTInstances.getLast().then(function (dtInstance) {
dtInstance.rerender();
});
}
|