ReloadData doesn't work
I can't do reload after crud(add/delete) operations in grid.
Can everybody tell me how can I do reload grid? Thanks
Depending on the renderer you are using:
- with the Angular renderer: you will need to do it directly on your model. It's no use to call
dtInstance.reloadData() - with the Promise renderer: it will clear the table, re-resolve the promise (so a request will be sent to the server to fetch the data) and call the draw() function.
- with the Ajax renderer: it will call the load() function.
So, check if the request is indeed sent to the server or that your CRUD operations have been indeed taken into account in your server.
I use angular-datatables with angular.js.
Tell me please how can I reach dtInstance.reloadData()?
Data I get from server
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.withOption('ajax', {
url: ngAuthSettings.apiServiceBaseUri + 'positionapi/GetOpenPositions',
type: 'GET',
dataSrc: 'data',
sAjaxSource: 'openPositions',
reloadData: function () {
this.reload = true;
return this;
},
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, GET, DELETE, PUT',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer ' + localStorageService.get('authorizationData').token
}
})
.withOption('fnRowCallback',
function (nRow) {
$compile(nRow)($scope);
})
.withOption('serverSide', true)
.withPaginationType('full_numbers')
.withBootstrap();
angular.module('yourModule', ['datatables'])
.controller('YourCtrl', YourCtrl);
function YourCtrl(DTOptionsBuilder, DTInstances) {
var vm = this;
var dtInstance;
vm.dtOptions = DTOptionsBuilder.newOptions();
vm.doSomeComplexStuff = doSomeComplexStuff;
DTInstances.getLast().then(function(instance) {
dtInstance = instance;
});
function doingSomeComplexStuff() {
// Do your things
dtInstance.reloadData();
// Do your other things
}
}
Grade! Now, my grid has full operations. Thanks for your help
I have same problem my code is here:
angular.module('ExchangesController', ['datatables'])
.controller('ExchangesCtrl', function ($scope, $compile, DTOptionsBuilder, DTColumnBuilder, DTInstances) {
var vm = this;
vm.exchanges = {};
var dtInstance;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
url: 'http://localhost:3000/ServiceProviders/Exchange',
type: 'POST'
})
.withDataProp('data')
.withOption('processing', true)
.withOption('serverSide', true)
.withOption('createdRow', createdRow)
.withPaginationType('full_numbers');
vm.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('username').withTitle('Username'),
DTColumnBuilder.newColumn(null).withTitle('Actions')
.renderWith(actionHtml)
];
DTInstances.getLast().then(function(instance) {
dtInstance = instance;
});
vm.edit = function (exchange) {
console.log('the exchange is ' + JSON.stringify(exchange) );
dtInstance.reloadData();
};
vm.delete = function (exchange) {
console.log('delete! the exchange is ' + JSON.stringify(exchange) );
dtInstance.reloadData();
};
function createdRow(row, data, dataIndex) {
// Recompiling so we can bind Angular directive to the DT
$compile(angular.element(row).contents())($scope);
};
function actionHtml(data, type, full, meta){
vm.exchanges[data.id] = data;
return '<button class="btn btn-warning" ng-click="exchanges.edit(exchanges.exchanges[' + data.id + '])">' +
' <i class="fa fa-edit"></i>' +
'</button> ' +
'<button class="btn btn-danger" ng-click="exchanges.delete(exchanges.exchanges[' + data.id + '])" )"="">' +
' <i class="fa fa-trash-o"></i>' +
'</button>';
};
});
and it shows me this error: Error: [$injector:unpr] http://errors.angularjs.org/1.4.7/$injector/unpr?p0=DTInstancesProvider%20%3C-%20DTInstances%20%3C-%20ExchangesCtrl at Error (native) at http://localhost:3000/vendor/angular/angular.min.js:6:416 at http://localhost:3000/vendor/angular/angular.min.js:40:409 at Object.d as get at http://localhost:3000/vendor/angular/angular.min.js:40:483 at d (http://localhost:3000/vendor/angular/angular.min.js:38:394) at e (http://localhost:3000/vendor/angular/angular.min.js:39:161) at Object.instantiate (http://localhost:3000/vendor/angular/angular.min.js:39:310) at http://localhost:3000/vendor/angular/angular.min.js:80:313 at A.link (http://localhost:3000/vendor/angular-route/angular-route.min.js:7:268)
How it will be Ok?
I fixed it my problem is I did't inject dtInstance in table tag.
I don't have DTInstances, I keep getting error from angular saying that there's no such service. :-(
Update your angular-datatables version.
v.0.5.4 wasn't released. Bower cannot update it if it wasn't released.
Very good! Thank's
i want also delete raw after refresh datatable but i can't know how can do that any one please let me know. i am use this version angular-datatable v0.5.2.