Load/Reload the table data from a promise function

In some case, you need to load some new data. This module handles data loading seamlessly.

angular.module('datatablesSampleApp', ['ngResource', 'datatables']) .controller('dataReloadWithPromiseCtrl', function($scope, DTOptionsBuilder, DTColumnBuilder, $resource) { $scope.reloadData = function() { $scope.dtOptions.reloadData(); }; $scope.changeData = function() { $scope.dtOptions.fnPromise = function() { return $resource('data1.json').query().$promise; }; // Or $scope.dtOptions.fnPromise = $resource('data1.json').query().$promise; }; $scope.dtOptions = DTOptionsBuilder.fromFnPromise(function() { return $resource('data.json').query().$promise; }).withPaginationType('full_numbers'); $scope.dtColumns = [ DTColumnBuilder.newColumn('id').withTitle('ID'), DTColumnBuilder.newColumn('firstName').withTitle('First name'), DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible() ]; });

data.json 
data1.json 

[{ "id": 860, "firstName": "Superman", "lastName": "Yoda" }, { "id": 870, "firstName": "Foo", "lastName": "Whateveryournameis" }, { "id": 590, "firstName": "Toto", "lastName": "Titi" }, { "id": 803, "firstName": "Luke", "lastName": "Kyle" }, ... ]