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

DTInstances.getList() nullpointerexception #232

Closed
bolemeus opened this issue Feb 27, 2015 · 6 comments
Closed

DTInstances.getList() nullpointerexception #232

bolemeus opened this issue Feb 27, 2015 · 6 comments
Labels

Comments

@bolemeus
Copy link

I have several datatables on a single page and I want to be able to filter the results on a date (date between this and that). I've made a custom filter for this and I want to include this in the request I make to the server when fetching the results. I use serverside processing by the way.

In order to do this I need to reload the data for all datatable instances whenever the user updates the date filter. I'm trying the following, but I get a nullpointerexception.

    DTInstances.getList().each(function(dtInstance) {
        dtInstance.reload();
    });

It seems the NPE occurs in the getList() method. Is this a known bug or have I messed something up? The datatables are already initialised when the method gets called.

@bolemeus bolemeus changed the title DTInstances nullpointer DTInstances.getList() nullpointerexception Feb 27, 2015
@l-lin
Copy link
Owner

l-lin commented Feb 27, 2015

There is a bug (check  #198) in the v0.4.0. It has been fixed for the upcoming version.
The DTInstances.getList() returns an object containing the list of datatables:

DTInstances.getList().then(function(dtInstances) {
    /*
     * This is the representation of dtInstances
     * dtInstances === {
     *      "foobar": {"id": "foobar", "DataTable": oTable, "dataTable": $oTable},
     *      "foobar2": {"id": "foobar2", "DataTable": oTable, "dataTable": $oTable}
     * }
     */

    // Suppose you want to use the DataTables "reload()" API to the "foobar" table 
    // See https://datatables.net/reference/api/ajax.reload()
    dtInstances.foobar.DataTable.reload();

    // If you want to use the angular-datatables "reloadData()" api
    // See http://l-lin.github.io/angular-datatables/#/dataReloadWithAjax
    dtInstances.foobar.reloadData();
});

@l-lin l-lin added the question label Feb 27, 2015
@bolemeus
Copy link
Author

bolemeus commented Mar 2, 2015

Hey l-lin,

Thanks for the reply. I've added the extra lines as in #198, and changed my code to:

    DTInstances.getList().then(function(dtInstances) {
        logger.info('list', dtInstances);
    });

But now the code logger.info(...) never gets called. The getList() method gets called but that's it. I also tried it with the getLast() method, but that yields thesame result.

@l-lin
Copy link
Owner

l-lin commented Mar 2, 2015

See this pen.

@bolemeus
Copy link
Author

bolemeus commented Mar 2, 2015

Hey l-lin,

When I rewrite my code like the pen it also works, but I don't get why it doesn't in my example. I forked your pen to show my scenario. See this pen

Anyway, I'll try to fetch all datatables instances at pageload and see if I can work with that.

@l-lin
Copy link
Owner

l-lin commented Mar 2, 2015

Mmh I didn't consider this use case. It's all about timing issue.
I created an issue #234 about this.

For now, you will have to stick with calling like in my pen. 😞

@bolemeus
Copy link
Author

bolemeus commented Mar 2, 2015

Ok, thanks 😄

I've already made a beginning using the code you provided in your pen and it's looking good sofar. 👍
I don't know if you want to close this. I think it's best becuase my original issue was a duplicate.

@l-lin l-lin closed this as completed Mar 2, 2015
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

2 participants