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

Postpone / remove init() for ajax loaded tables #10

Open
antanova opened this issue Apr 28, 2016 · 2 comments
Open

Postpone / remove init() for ajax loaded tables #10

antanova opened this issue Apr 28, 2016 · 2 comments

Comments

@antanova
Copy link

Hi, this is a very minor issue indeed. I have empty table tags like this

<table class="sortable" data-source="http://example.com/data/source"></table>

on my page, and a script then loads the rest of the table in on page load. So far, so good.

The problem I'm having is that as soon as the DOMReady event happens, sorttable.init() is triggered. Now, because the table tag above is empty, I get a js error: 'Argument 1 of Node.appendChild is not an object'. The error is coming from the following line in makeSortable():

the.appendChild(table.rows[0]);

Presumably, that's because there are no rows. The error isn't blocking or causing any problems, but as I found it I thought I should add it here.

@stuartlangridge
Copy link
Owner

Sorttable ought to handle this situation better, I agree, so I'll leave this open, but as a workaround I'd suggest not applying class="sortable" until you first load data into the table, and then calling sorttable.makeSortable() after that.

@antanova
Copy link
Author

antanova commented May 3, 2016

Thanks, I'll give that a go. At the moment, I'm triggering an event when the table content has loaded, then calling makeSortable() within the event callback. I'll add the class in that same callback now, just to get rid of the error.

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

No branches or pull requests

2 participants