Removing whitespace in table headers

Removing whitespace in table headers

wdupreewdupree Posts: 5Questions: 0Answers: 0
edited September 2011 in Bug reports
I found that if I formatted the HTML so that the headers were like this:

[code]

Something

[/code]

instead of like this:
[code]
Something
[/code]

Then Datatables picked up all the carriage returns and whitespace - but didn't in the values. I noticed that back in 1.7 Datatables was changed to use $.trim to remove the whitespace of value cells - but this wasn't done for the header cells. If you change line 2342 (using version 1.8.2) from:

[code]
"sTitle": nTh ? nTh.innerHTML : '',
[/code]

to

[code]
"sTitle": nTh ? $.trim(nTh.innerHTML) : '',
[/code]

It trims all the header text so that it doesn't show up in PDFs, CSVs and Excel exports. Hope that helps others and can be added to future versions. Thanks for all the great work!

Replies

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Thanks for the tip - in 1.8 there was a general shift to try and interfere with the data that you give the data as little as possible, hence why this was changed. However, a little while ago (a week or two) there was a commit into TableTools which will do a trim on headers - so that's another option (its currently in the nightly).

    Allan
  • wdupreewdupree Posts: 5Questions: 0Answers: 0
    Allan,

    Just to give you a heads up - I tried the 1.8.3.dev file that's currently on the site and it still does this for me in the header and footer. Plus, I found that if I added the following at line 2817:

    [code]
    anCells[i].innerHTML = $.trim(anCells[i].innerHTML);
    [/code]

    If got rid of the extra spaces in the footer cells. Hope that helps.
This discussion has been closed.