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.
This API is deprecated.
From v0.5.0+, the DTInstances.getLast()
and DTInstances.getList()
will be removed.
Use the dt-instance
directive instead!
See the documentation for more information.
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": function(callback, resetPaging),
// "changeData": function(newData),
// "rerender": function()
// }
// 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": function(callback, resetPaging),
// "changeData": function(newData),
// "rerender": function()
// },
// "foobar2": {
// "id": "foobar2",
// "DataTable": oTable,
// "dataTable": $oTable,
// "reloadData": function(callback, resetPaging),
// "changeData": function(newData),
// "rerender": function()
// }
// }
});
}
|
DTInstance |
reloadData(callback, resetPaging) |
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();
});
}
|