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

Sorttable complains if the table has no body (and fix) #34

Open
RichardNeill opened this issue Apr 15, 2022 · 0 comments
Open

Sorttable complains if the table has no body (and fix) #34

RichardNeill opened this issue Apr 15, 2022 · 0 comments

Comments

@RichardNeill
Copy link

  1. It is possible, when auto-generating tables, to have a table with 1 (or more) header rows, 1 (or more) footer rows, and zero main rows in the table.
<thead>
<tr>...</tr>
</thead>
<tfoot>
<tr>...</tr>
</tfoot>
  1. If the table contains an explicit <tbody></tbody> section, then sorttable handles it fine.

  2. But in the usual case, where the <tbody> tags are omitted (because they are considered implicit) AND the table has no main rows (i.e. there are no <tr> that come after <thead> and before <tfoot>), then sorttable complains and generates JS errors.

  3. The fix is to add the following, in makeSortable, just after the test for table.tHead == null:

//If there is no table body (no <tbody>, nor is it implicit because of a normal <tr>), then give up. Otherwise, we get errors later.
if (table.getElementsByTagName('tbody').length == 0){
    //console.log ("disembodied table.");
    return;
}
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

1 participant