2

I am having a problem with the data tables jquery plugin where my headers are not aligning properly with the table. I noticed that if I add cellspacing=0 to the table it will align correctly. However, this attribute isn't supposed in HTML5 and I would like this to work in HTML5 as well if possible. If you look at the dotted border lines, the header ones do to match the content table lines.

Here is the javascript I am using to create the table.

myTableHere = $('#MyTableHere').dataTable({
    'sScrollY': '100px',
    'bPaginate': false,
    'bScrollCollapse': true,
    'bFilter': false,
    'bInfo': false,
    'bSort': false,
    "aoColumns": [
        { "sWidth": "95px" },
        { "sWidth": "267px" },
        { "sWidth": "77px" },
        { "sWidth": "90px" },
        { "sWidth": "90px" },
        { "sWidth": "42px" }
    ]
});

This is being viewed in the latest version of chrome. enter image description here

Here is some sample HTML before I data tablefy it. https://gist.github.com/anonymous/d44360d3a06c1a5b2898

Edit: I found that by adding border collapse to the header table, it solved the issue.

9
  • Can you add some sample HTML of your table (with headers and some actual rows)? Commented Mar 20, 2013 at 15:00
  • HTML pre "datatabled" or post "datatabled" Commented Mar 20, 2013 at 15:02
  • pre -- what are you starting with. Commented Mar 20, 2013 at 15:03
  • I believe I see a scrollbar for the table body. I wonder if that factors in. Also, to facilitate the scrollbar, is the "header" actually a separate table from the table itself (whether by your code explicitly or as an "automagic" feature of the API)? Even when specified as pixel values, column widths are always subject to adjustment by the browser, so it's kind of a craps shoot putting tables on top of one-another and hoping they'll line up. Commented Mar 20, 2013 at 15:07
  • 1
    I found that by adding border collapse to the header table, it solved the issue. Commented Mar 20, 2013 at 16:26

1 Answer 1

1

On the table that I was using the data tables plugin on, I had a the border-collapse: collapse; css property applied to it. This property was still being applied to the content table after the plugin had finished tablfying my table. However, the seperate header table did not have this css property applied to it as well. After setting the header table to also be border collapse, the lines lined up properly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.