Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm trying to load data from an ajax source into angular datatable but it's not even hitting the ajax call.

var analyzer=angular.module('analyzer', ['datatables']);
analyzer.controller('WithAjaxCtrl', WithAjaxCtrl);

            function WithAjaxCtrl(DTOptionsBuilder, DTColumnBuilder) {
                    var vm = this;

                    $scope.dtOptions = DTOptionsBuilder.fromSource('/analyzer/List')

                    $scope.dtColumns = [
                    DTColumnBuilder.newColumn('BuildName').withTitle('Name'),
                    DTColumnBuilder.newColumn('Total').withTitle('Total'),
                    DTColumnBuilder.newColumn('Passed').withTitle('Passed'),
                    DTColumnBuilder.newColumn('Failed').withTitle('Failed')

                ];
            }

Here's the html code for the table-

<div ng-controller="WithAjaxCtrl">
     <table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="row-border hover"></table>
</div>

data from ajax source is in the form -

{"responseCode":0,"responseData":[{"Name":"Rob","Total":6273,"Passed":5874,"Failed":399}]}

So will i have to define the datasrc ?

share|improve this question
up vote 1 down vote accepted

Yes, you need to specify the dataSrc since your rows is contained in responseData, not in the default or expected data property. In angular dataTables there is an option setter named withDataProp() :

$scope.dtOptions = DTOptionsBuilder.fromSource('/analyzer/List')
  .withDataProp('responseData')

Cannot link directly but look at https://l-lin.github.io/angular-datatables/#/api

share|improve this answer

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.