Skip to content

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

Description

@RichardNeill
  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;
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions