Cannot read property 'aDataSort' of undefined in angular datatables Cannot read property 'aDataSort' of undefined in angular datatables angularjs angularjs

Cannot read property 'aDataSort' of undefined in angular datatables


You are passing showCase.dtOptions and showCase.dtColumns to the datatables directives when the page loads, but they are not declared until after your service call is completed. One workaround for this would be to use ng-if to construct the html after the service call:

<table ng-if="showCase.authorized" datatable="" ...

Then in your controller, initialize the variable before calling the service, and updating it after the call is complete:

app.controller('WithAjaxCtrl', function WithAjaxCtrl(DTOptionsBuilder, DTColumnBuilder, UserService) {  var vm = this;  vm.authorized = false;  UserService.get()...

Here is a demo. You can reproduce the error by removing the ng-if. http://plnkr.co/edit/XZYOEvgy1HoMYGmGdAYj?p=preview


Please make sure your <th> are inside of <thead> in your table structure.

Example:

<thead>   <tr>     <th> name </th>     <th> email </th>   </tr></thead>