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

bad markup in programmatic data-table column headers #1015

Closed
rjmorris opened this issue Sep 20, 2015 · 2 comments
Closed

bad markup in programmatic data-table column headers #1015

rjmorris opened this issue Sep 20, 2015 · 2 comments
Labels
Milestone

Comments

@rjmorris
Copy link

PR #668 introduced a way to specify the columns of a dataTable programmatically, so that you don't have to place them in your HTML. However, the markup it creates isn't correct as far as I can tell. You can see this in the example at http://dc-js.github.io/dc.js. The generated markup looks something like:

<table>
    <th>Date</th>
    <th>Open</th>
    ...
    <tbody>
        ...
    </tbody>
</table>

According to the HTML spec, the only permitted parent of th is tr; it shouldn't be a direct child of table. It's also good practice to put the tr inside a thead. Therefore, I think the generated markup should look like this instead:

<table>
    <thead>
        <tr>
            <th>Date</th>
            <th>Open</th>
            ...
        </tr>
    </thead>
    <tbody>
        ...
    </tbody>
</table>

I've worked around this by adding the following to my postRender and postRedraw hooks:

var headerGroup = $('<thead>').prependTo('#staff-table');
var headerRow = $('<tr>').appendTo(headerGroup);
$('#staff-table th').detach().appendTo(headerRow);

Without the workaround, things don't work right when I try to pass the DC dataTable into the jquery DataTable plugin, because the plugin can't detect the header row.

@gordonwoodhull
Copy link
Contributor

Thanks for the report @rjmorris. Ah HTML and its implicit tags! (Or is it the browsers and their too-helpful guessing? I'm never sure.)

I agree with your analysis. This should be an easy and safe fix.

@gordonwoodhull gordonwoodhull added this to the v2.0 milestone Oct 6, 2015
@rjmorris
Copy link
Author

rjmorris commented Oct 6, 2015

Ah HTML and its implicit tags! (Or is it the browsers and their too-helpful guessing? I'm never sure.)

Ha, well I'm OK with blaming both.

gordonwoodhull added a commit that referenced this issue Dec 22, 2015
partly to have a better example for #1015
gordonwoodhull added a commit that referenced this issue Dec 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants