Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am using angular-datatables with server side processing. When you specify the datatable attribute in table it will be transformed as datatable. But I want to manually do this after resolving one Ajax request.

$scope.dtOptions = DTOptionsBuilder
 .newOptions()
 .withOption('ajax', {
   url: config.apiBasePath + '/getTasks',
   type: 'GET',
   beforeSend: (xhr)->
    xhr.setRequestHeader('access-token', $scope.user.api_key)
    xhr.setRequestHeader('uid', $scope.user.uid)
  })
.withDataProp('data')
.withOption('processing', true)
.withOption('serverSide', true)
.withPaginationType('full_numbers')

$scope.dtColumns = [
 DTColumnBuilder.newColumn('title').withTitle('Title'),
 DTColumnBuilder.newColumn('keywords').withTitle('Keywords')
 DTColumnBuilder.newColumn('number_of_completions').withTitle('Number Of Completions')
 DTColumnBuilder.newColumn('reward_per_completion').withTitle('Reward Per Completion')
]

In the above code datatable ajax request should be initiated after $scope.user resolved. Else I am getting 401.

I don't see any doc to manually setup datatables. Any idea?

share|improve this question

You can use the ngIf directive. The content will be processed only when the condition is met:

<div ng-if="user">
    <table datatable dt-options="dtOptions" dt-columns="dtColumns"></table>
</div>

In this example, if the user is not defined or null, then the condition is not met. Only when you assign $scope.user will the condition be met.

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.