Dynamic columns in angular datatable

47 views
Skip to first unread message

Komal Shah

unread,
Oct 24, 2018, 2:59:37 PM10/24/18
to Angular and AngularJS discussion
We are using $http to get array of columns and then bind it to dtColumns object of angular datatable.
But before the bind code is called, 'aDatasort is not defined ' error occurs.

Below is the html code
 <table datatable="" dt-options="showCase.dtOptions"  class="row-border hover"></table>

Below is the Controller code
($scope.col is the array of columns which are build using $http)



vm.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('ajax', {
         // Either you specify the AjaxDataProp here
         // dataSrc: 'data',
         url: ../api/Page/data',
         type: 'POST',
     dataSrc: function(json) {
           console.log(json);
  var names = json.columns;

 
          return json.data;
        },
     })
     // or here
     .withDataProp('data')
        .withOption('processing', true)
        .withOption('serverSide', true)
.withDisplayLength(10) 
        .withPaginationType('full_numbers');
 
 
 vm.dtColumns =  $scope.col;

Sander Elias

unread,
Oct 25, 2018, 8:02:16 AM10/25/18
to Angular and AngularJS discussion
Hi Komal

I'm pretty sure this question is answered before in this group. Did you search for it?

Regards
Sander

Komal Shah

unread,
Oct 25, 2018, 12:06:05 PM10/25/18
to Angular and AngularJS discussion
Yes I have search and there are results for it, but I am specifically looking for a scenario
where my api call happens after , and the datatable is already initialise as a part of directive in table tag.
How do I handle such scenario ?
Reply all
Reply to author
Forward
0 new messages