lightswitch05/table-to-json

Rowspan not supported

Closed this issue · 8 comments

An HTML table may contain cells that span multiple rows (or columns, for that matter). This is not handled in table-to-json. Please see JSfiddle example at http://jsfiddle.net/perqa/4E2L6/.

baw commented

Thanks for your issue. One way I think this could be handled is by including a row/column that spans multiple rows/columns to all they span. Do you have any other ideas of how this could be handled?

DV3 on Stackoverflow claims to have fixed this. We'll give him some time to submit a pull request.

It messes up even worse if the thead has multiple rows (demo):

<table border="1" id="example-table">
    <thead>
        <tr>
            <th rowspan="2">line</th>
            <th colspan="2">values</th>
        </tr>
        <tr>
            <th>value1</th>
            <th>value2</th>
        </tr>
    </thead>
    <tbody>
        ...
    </tbody>
</table>

@Mottie - you might be able to fix the headings by using the headings option. You just pass in an array of the headings you want and it will use those over any headings defined in the table. But obviously support for rowspan and colspan is needed.

See PR #10

Updated demo

Note: I just realized I didn't test to make sure this change will work if the first column of a colspan is set to be a hidden column...

@Mottie, your PR has been merged and released in v0.8.0. If you would like to add more tests and help out with future features/bugs I've added you as a Collaborator to the project

Thanks, I appreciate that!

After working to incorporate the same code I added into a tablesorter widget, I discovered that it doesn't correctly parse a cell with both a rowspan and colspan. It'll take a bit more tweaking to get it to work properly. So until then, I wanted to make sure everyone was aware of this limitation.

Added support to allow for cells that have both a rowspan and a colspan in 9f80cef. I still haven't had a chance to look into making it work with hidden columns.