How to use a local JSON object with angular-datatables How to use a local JSON object with angular-datatables angularjs angularjs

How to use a local JSON object with angular-datatables


I had a similar problem to the OP and Mica's answer was very helpful in pointing me in the right direction. The solution I used was as follows:

var getTableData = function() {    var deferred = $q.defer();    deferred.resolve(myTableDataObject);     return deferred.promise;};

Then use that in the DTOptionsBuilder:

$scope.dtOptions = DTOptionsBuilder.fromFnPromise(getTableData)    .withPaginationType('full_numbers');

I'm fairly new to Angular, and indeed JavaScript, so there may well be a more elegant/correct way of doing this, but it worked for me.


You can't use .fromSource as it always will do an ajaxUrl request. But you can use .fromFnPromise() instead. Put your JSON into a function which returns an deferred.promise.