LeeWannacott / table-sort-js

HTML table sorting with no dependencies.
https://cdn.jsdelivr.net/npm/table-sort-js@latest/table-sort.js
MIT License
73 stars 27 forks source link

TypeError: tableBody is null #93

Closed strager closed 1 year ago

strager commented 1 year ago

If I create a table without a <tbody>, the table-sort-js browser extension crashes with TypeError: tableBody is null.

<section id="log-section">
  <table id="log-table">
    <thead>
      <tr>
        <th>file offset</th>
        <th>stream</th>
        <th>stream offset</th>
        <th>message</th>
      </tr>
    </thead>
  </table>
</section>
LeeWannacott commented 1 year ago

Sounds fixable it's because the browser extension applies table-sort tag to all tables. I could create a tbody if it doesn't exist (Like I do with <thead>) ,or just exit out, or do a check for null before trying to grab tbody.

function makeTableSortable(sortableTable) { const tableBody = getTableBody(sortableTable); const tableHead = sortableTable.querySelector("thead"); const tableHeadHeaders = tableHead.querySelectorAll("th"); const tableRows = tableBody.querySelectorAll("tr");

It's this line here.

LeeWannacott commented 1 year ago

Should be fixed in: https://github.com/LeeWannacott/table-sort-js/pull/99