Skip to content
This repository has been archived by the owner on Feb 2, 2025. It is now read-only.

Delay render to define dtColumns using promises #22

Closed
lius opened this issue Jul 11, 2014 · 7 comments
Closed

Delay render to define dtColumns using promises #22

lius opened this issue Jul 11, 2014 · 7 comments
Labels

Comments

@lius
Copy link
Contributor

lius commented Jul 11, 2014

Hey Louis,

I have a scenario where my DTColumns are defined by rules on server side, that returns an array with columns. I'm getting a error because datatables rendering cannot wait for columns definition (like the behaviour support for data) arriving after controller execution.

My ideia is to implement support to define columns using promises, alongside "static" way, through a delay on datatables rendering.

What you think? Any advices?

@l-lin
Copy link
Owner

l-lin commented Jul 12, 2014

I don't think it's a good idea to add more complexity to the module.
This module was designed so that it's easy to build DataTable options.

Maybe there is an another way to solve your problem, like loading your column options before rendering the template where your DataTable is.

@l-lin l-lin added the wontfix label Aug 28, 2014
@l-lin l-lin closed this as completed Aug 28, 2014
@giolvani
Copy link

I have the same problem, I need define which columns to display by server side request.
:(

@giolvani
Copy link

I made a workaround for this problem. I just set the table to display after columns are defined...

<table ng-if="showDT" datatable dt-options="dtOptions" dt-columns="dtColumns"></table>
//options definitions
$scope.dtOptions = DTOptionsBuilder.newOptions()
    .withOption('ajax', { url: 'http://localhost/data.json' });

//coluns definitions
var dtColumns = [];

//request columns config
$http.get('http://localhost/config-columns.json').
    success(function(data) {
    // this callback will be called asynchronously
    angular.forEach(data, function(column){
        dtColumns.push(DTColumnBuilder.newColumn(column.Name));
    });
});

//set columns
$scope.dtColumns = dtColumns;

//show datatable
$scope.showDT = true;

It may be weird, but works for me!

@l-lin
Copy link
Owner

l-lin commented Oct 23, 2014

I'm considering accepting a promise in the dtColumns and dtColumnDefs attributes and using $q.when in the directive to resolve this issue.
Still need to POC it.

@giolvani
Copy link

Sure!
This was a stopgap measure... ;)

@f0def
Copy link

f0def commented Mar 31, 2015

I also need this functionality

@windmaomao
Copy link

I have to say, I found the right thread for my problem.

Basically ng-repeat on thead th is not going to be resolved before the directive is rendered. So I'll try the above approaches.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants