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

Tables with rowspans not sortable #71

Closed
coljac opened this issue Mar 26, 2024 · 2 comments
Closed

Tables with rowspans not sortable #71

coljac opened this issue Mar 26, 2024 · 2 comments

Comments

@coljac
Copy link

coljac commented Mar 26, 2024

For a table with rowspan="n", the sorting leads to a broken table display. Here's an example:

<html><body>
<table class="sortable">
  <thead>
    <tr>
        <th>Class</th>
      <th><span>Role</span></th>
      <th>Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
        <td rowspan="2">Main Character</td>
      <td>Aenius</td>
      <td>Bird Person</td>
    </tr>
    <tr>
      <td>Genius</td>
      <td>Rick</td>
    </tr>
    <tr>
        <td>Comic Relief</td>
      <td><a href="javascript:alert('Inline javascript works!');">Sidekick</a></td>
      <td>Morty</td>
    </tr>
  </tbody>
</table>
<link href="/assets/sortable.min.css" rel="stylesheet" />
<script src="/assets/sortable.min.js"></script>
    </body></html>

Expected result: It treats a rowspan as a single row for sorting purposes.
Actual result: The table is scrambled, sometimes columns are added.

before
after1

@tofsjonas
Copy link
Owner

I have racked my brain trying to figure out a solution, but if it works for this it breaks in other ways.

The problem with rowspans is that they affect the row(s) following the current one. So to not break the table we would have to group them and lock them to that group. This could probably work for the column that has the rowspan, but sorting would break for all the other columns, since they cannot be allowed to split the group.

(Not to mention what would happen if a row has multiple columns with rowspans. Or overlapping rowspans from other rows. 🫣)

I am sorry, but I think it may not even be theoretically possible 🤯😢

@phil2phil
Copy link

Atomize the row span by duplicating the content in the spanned rows. When sorting, the row span would have to be torn apart. There is no other option.

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

3 participants