-
Notifications
You must be signed in to change notification settings - Fork 490
Usage with Restangular #103
Comments
It should work with angular.module('datatablesSampleApp')
.controller('withPromiseCtrl', function ($scope, DTOptionsBuilder, DTColumnBuilder, Restangular) {
$scope.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
return Restangular.all('data').getList();
}).withPaginationType('full_numbers');
$scope.dtColumns = [...];
...
}); |
Thanks for this, I have notifications switched off and didn't realise you'd responded so quick! The solution kind of works but the response is returned as the value of an object called 'records' and the main issue is I'm not sure how to access the array within it using this method. So whilst it loads the tables has no data. Thanks |
Then you need to wrap it to another promise using angular.module('datatablesSampleApp')
.controller('withPromiseCtrl', function ($q, $scope, DTOptionsBuilder, DTColumnBuilder, Restangular) {
$scope.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
var defer = $q.defer();
Restangular.all('data').get().then(function(result) {
// Suppose your data is nested in the "data" attribute of your response
defer.resolve(result.data);
});
return defer.promise;
}).withPaginationType('full_numbers');
$scope.dtColumns = [...];
...
}); However, in the version that will come, I just implemented the feature #111 that will permit you to set a angular.module('datatablesSampleApp')
.controller('withPromiseCtrl', function ($scope, DTOptionsBuilder, DTColumnBuilder, Restangular) {
$scope.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
return Restangular.all('data').getList();
})
.withDataProp('data') // If your data is nested in the "data" attribute
.withPaginationType('full_numbers');
$scope.dtColumns = [...];
...
}); |
I've actually just cracked it with a similar solution to your first option :) so this worked for me:
I'll keep an eye out for the next stable version. Thanks again for the help! 👍 |
How can I use server side pagination with Restangular? When I enable "withOption('serverSide', true)", Datatables will call the API twice: A regular call and a datatables call passing datatables values but without the route "api/clientes". https://s31.postimg.org/xz3v7q9bf/datatables.jpg I'm trying this code but with no success. How can I solve this?
|
@thiagosoeiro Have you found a solution? DTOptionsBuilder
.newOptions()
.withOption('ajax', function(data, callback, settings) {
const Resource = Restangular.all('clientes');
const req = Resource.getList()
.then(function(resp) {
callback(resp.data);
});
}); |
Hi, i was wondering if anyone tried having it with a server side pagination? |
Yes, I did. There is an example code from my current project:
|
if anyone tried to refresh table data ? |
Hi, does anyone know which helper I would use to get data from Restangular? I assumed it would work exactly the same as the fnPromise example however it would appear not! Any thoughts or examples would be much appreciated.
Thanks
The text was updated successfully, but these errors were encountered: