Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load new column properties after table loaded #172

Closed
Sawtaytoes opened this issue Jan 9, 2015 · 9 comments
Closed

Can't load new column properties after table loaded #172

Sawtaytoes opened this issue Jan 9, 2015 · 9 comments
Milestone

Comments

@Sawtaytoes
Copy link

Is there a way to reload column properties after the table's been loaded?

I've got tabs setup in my project and when clicking a tab, it sends a new data object in the resolve of a promise. The issue is when clicking one of the tabs, the render function on one of the columns changes, but it's not being run to show currency instead of numbers.

I noticed you could do $scope.dtOptions.fnPromise = () like you did here: https://l-lin.github.io/angular-datatables/#/dataReloadWithPromise. But I believe the intended way is $scope.dtOptions.withFnPromise(). This is important because if you can do that, then there must be some way to modify the column properties after the table's loaded such as $scope.dtOptions.aoColumns = table.columns.

In angular-datatables.js:420, I see angular.extend(options, dtOptions);. Does this have anything to do with why options aren't mutable after the fact?

@l-lin
Copy link
Owner

l-lin commented Jan 9, 2015

These helpers (withXXX()) are not mandatory.
Writing

$scope.dtOptions = DTOptionsBuilder.newOptions()
    .withPaginationType('full_numbers')
    .withDisplayLength(2);

is the same as writing

$scope.dtOptions = {
    paginationType: 'full_numbers',
    displayLength: 2
};

Can you provide a plnkr or something alike to illustrate your issue?

@Sawtaytoes
Copy link
Author

I cannot easily do that no. Here's an example of what I'm doing:

setSelectedTable = function() {
    $scope.dtColumns = table.columns;
    $scope.dtOptions.withFnPromise(deferredReportFactory.getPromise(tableData));
};

deferredReportFactory takes JSON data and creates a promise then pushes that promise into dtOptions. I am able to swap this data just fine so this part is working as I'd like.

When I swap out dtColumns though, the column definitions are the same as the initial directive load, they don't get altered. So if one of the columns was setup to render numbers and that same column in the next table has the values as currency, they will render as numbers, not currency.

Is it possible to change this so I'm able to setup dtColumns again once the table is loaded if I reset the scope variable?

I even tried doing:

$scope.dtOptions.withOption('aoColumns', table.columns)

and

$scope.dtOptions.withOption('columns', table.columns)

But these didn't work either.

@l-lin
Copy link
Owner

l-lin commented Jan 16, 2015

In the current version, you cannot do it. There were an issue (#139) about the fact that the promise renderer cannot change the options.

In the upcoming version (v0.4.0), you will be able to change them like this.

@Sawtaytoes
Copy link
Author

That's that I'm lookin' for!

How can I get a hold of this version right now to test it out? Is it in a stable-enough state?

@l-lin
Copy link
Owner

l-lin commented Jan 16, 2015

It's all on the dev branch. There are still some development left before releasing a new version.

@Sawtaytoes
Copy link
Author

Using that branch as a test, it fails to load any table data from the promise and no errors. Has anything changed other than the removal of the dtOptions.reloadData() function?

@l-lin
Copy link
Owner

l-lin commented Jan 16, 2015

Take a look at the plnkr on my previous post. It's using the dev version. Try to imitate the code.

@l-lin l-lin added this to the v0.4.0 milestone Jan 20, 2015
@l-lin l-lin closed this as completed Jan 23, 2015
@Sawtaytoes
Copy link
Author

I spend a long time doing a revamp of my codebase with the newly released 0.4.0 and it still doesn't work as expected sadly :/.

I'm getting this to work only part of the time now. Sometimes it works and displays table data with the correct render function, sometimes it does not and shows the data then quickly hides it. The time where it hides the data and shows No data available in table seems to be when switching the render function, but it's only sometimes.

It appears this happens if I change out the class on one of the columns. If I don't change the class and only change one of them from numbers to currency, then absolutely no change occurs.

Have you tried swapping out the render function before and seen how it reacts?

@l-lin
Copy link
Owner

l-lin commented Jan 27, 2015

I'm not quite to understand your issue. Can you modify my previous plnkr to illustrate your problem?

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

No branches or pull requests

2 participants