2

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);

})

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.