Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

With Angular Datatables I want to pre-load a JSON object with Ajax so that I can re-use the object elsewhere without doing another ajax request. But how do I load this object into the datatable?

    .controller('ResponsiveDatatableCtrl', function ($scope, $rootScope, DTOptionsBuilder, DTColumnBuilder, apiserv, $filter, $state, $http) {


    $scope.dataLoading2 = true;
    var vm = this;  
    var data = "?db="+ $rootScope.globals.currentUser.agents[$rootScope.globals.currentDB].db_name;
    var url = apiserv+"api.files.php"+data;

    var headers = {'Content-Type': 'application/x-www-form-urlencoded'};
    $http({
        method: 'POST',
        url: url,
        headers: headers,

    })
        .success(function (response) {
            $rootScope.globals.files = response;
            $scope.dataLoading2 = false;
            //console.log($rootScope.globals.files);


        });

    vm.dtOptions = DTOptionsBuilder.fromFnPromise($rootScope.globals.files)
        .withPaginationType('full_numbers')
        .withBootstrap() 
        .withOption('responsive', true);

})
share|improve this question

Ok I have attempted the following and it seems to call my code under success but then the table doesn't update?

    vm.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
        url: url,
        type: 'POST',
        headers: headers,
        data: function(data, dtInstance) {

        },
        success: function(response) {
            $rootScope.globals.files = response;
        }
    })
        .withPaginationType('full_numbers')
        .withBootstrap()
        .withOption('responsive', true);
share|improve this answer
    
Ok I believe the answer to my question is assigning the DataTable to an instance, and then call the redraw/rerender function. I will add some code as soon as I can – johan Apr 21 '16 at 13:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.