Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Colspans in columntoggle mode #221

Closed
apdrsn opened this issue Aug 3, 2016 · 4 comments
Closed

Colspans in columntoggle mode #221

apdrsn opened this issue Aug 3, 2016 · 4 comments
Milestone

Comments

@apdrsn
Copy link

apdrsn commented Aug 3, 2016

Hi, and thanks for your great work on tablesaw :)

Is it possible to get the table to behave correctly when using colspans? Here is an example:

<table data-tablesaw-mode="columntoggle">
    <thead>
        <tr>
            <th data-tablesaw-priority="persist">Name</th>
            <th data-tablesaw-priority="1">Budget</th>
            <th data-tablesaw-priority="2">Actual</th>
            <th data-tablesaw-priority="persist">Total</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="3">Total</td>
            <td>150</td>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>Some name</td>
            <td>10</td>
            <td>30</td>
            <td>120</td>
        </tr>
        <tr>
            <td>Some other name</td>
            <td>20</td>
            <td>15</td>
            <td>30</td>
        </tr>
    </tbody>
</table>

What will happen when I toggle one of the columns off, is that colspan will still occupy three cells, even though it "should" only take two.

I'm aware that it is a bit complex – because which colspan should you take one cell from in case there were several cells with colspans?

Well, just wanted to ask if this is something you have solved before?

@jgibson
Copy link
Contributor

jgibson commented Aug 8, 2016

AFAICT tablesaw doesn't support rowspans or colspans in the data. Colspans in the headers are respected, however. Taking a look at initCells (as of 2.0.3) you can see that Tablesaw scans the table headers and then assigns the cells in the rows that correspond to each header to be toggled on or off later. Unfortunately the assignment algorithm ignores any colspans in the data. If you were to change your footer to look like this:

<tfoot>
        <tr>
            <td>Always here</td>
            <td colspan="2">Total</td>
            <td>150</td>
        </tr>
</tfoot>

Then I'd expect that toggling off the Budget column would hide the total column in the footer, but that the Actual column would have no effect on it (probably it would instead hide the 150 cell in the footer).

I adjusted the assignment algorithm to allow colspans in the data, but with the caveat that a cell with a colspan in the data can't cross multiple columns in the header. I'll submit a PR or something so that others can take advantage of it.

Your problem is thornier because instead of simply hiding or showing cells you'd have to adjust the colspan of your data cells on the fly. Taking a look at issue #48 you can see that other people have the reverse requirement (complex colspans and row spans in a multirow header). I can't see a way to provide the functionality that would satisfy both of you without a creating a comprehensive model of the table (as opposed to just assigning a group of cells to a single column header) and increasing the complexity of the toggling algorithm.

@jgibson
Copy link
Contributor

jgibson commented Aug 8, 2016

I opened #225 for the simple case that I described above.

@apdrsn
Copy link
Author

apdrsn commented Aug 9, 2016

Thank you very much! I will take a deeper look when I return from vacation.

@zachleat zachleat added this to the 2.0.4 milestone Sep 1, 2016
@zachleat
Copy link
Member

#225 has been merged and is available in the early 3.0 betas

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

No branches or pull requests

3 participants