It's weird in calculating table width

It's weird in calculating table width

linuslinus Posts: 8Questions: 0Answers: 0
edited October 2013 in DataTables 1.9
In _fnCalculateColumnWidths function, you calculated the width of created temporary table "nCalcTmp". Why don't you use width() method directly, but by summing one by one visible column. Since this temporary has been added into page, and its result is wrong when "border-spacing" is used.

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Because table column widths are a nightmare in browsers. border-spacing, border-collpase etc can all seriously mess up the column width calculation. So what DataTables does is it reads the width of each column, as you suggest, but also reads the width of the whole table - because (mentally enough) the column widths often do not add up to the table width... Short of using browser detection and monitoring each version of each browser, this was the best fall back I could think of.

    Allan
  • linuslinus Posts: 8Questions: 0Answers: 0
    I have an idea on calculating column width. After you getting the longest value, replace the string with some long characters, like "M", and put it into TD. For example, "asdf" will be altered to "MMMM" in TD. Using this method, you may don't need the sContentPadding any more. Obviously, it's not visible to user, you just need to get the biggest width.
  • linuslinus Posts: 8Questions: 0Answers: 0
    edited October 2013
    Maybe digital number with "0", lowercase with "w", uppercase with "W". I think you can add a option, it should be OK for just text values.
  • linuslinus Posts: 8Questions: 0Answers: 0
    Hmm, after my testing, it's not a good idea. Forget what I had said!
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Yup, I'm not too keen in replacing the content. I did, in one of the 1.5 beta's years ago, replace the widest node function with a function which actually put the data into an HTML element and got the width - that was absolutely perfect every time, but unbelievably slow. It was removed in the next beta a few days later...

    Allan
This discussion has been closed.