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 →

How can I load angular datatables column names from a json data response from an ajax call? I'd like not to have to explicitly name the columns (e.g. DTColumnBuilder.newColumn('AeId').notVisible() ).

contoller.js

function dashboardAeReportCtrl($scope, dataService, DTOptionsBuilder, DTColumnBuilder, DTRenderer) {

  var vm = this;
  vm.dtInstance = {};
  vm.dtOptions = DTOptionsBuilder.newOptions()
  .withOption('ajax', {
        type: 'POST',
        dataSrc: 'data',
        url: dataService.dashboard.aeReport.route,
        data: function (d) {
              //doesn't work
              vm.dtColumns = d.columns;
        }
  })
  .withOption('processing', true)
  .withOption('serverSide', true)

   //does work but column names are hard coded
   vm.dtColumns = [
    DTColumnBuilder.newColumn('AeId').notVisible(),
    DTColumnBuilder.newColumn('AE').withTitle('AE'),
 ];

}

view.html

<table datatable="" dt-instance="vm.dtInstance" dt-options="vm.dtOptions" dt-columns="vm.dtColumns"></table>
share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.