Column width issues in DT 2.3.5

Column width issues in DT 2.3.5

palkittpalkitt Posts: 5Questions: 1Answers: 0

Link to test case:
https://live.datatables.net/zetukeke/3/edit

Description of problem:
Thanks for a great product that makes life good :-)

When switching to the latest release of DT, 2.3.5, my tables got a bit messed up. I have boiled it down to the cases demonstrated in the test case.

I think things went wrong in this commit:
https://github.com/DataTables/DataTablesSrc/commit/8b2d742ca039f06ed2724bb5b4c25577c50393bd

In version 2.3.4 (try to swap in the test case), the longest string used to calc the column width was the cellString, whereas in the new version it is the stripped HTML string from cellString that is used and any formatting get lost. Also, the new function with 3 longest string parts seem to cause some trouble in the case where the string includes numeric character reference (and maybe more).

I hope this helps you on the way to the solution!

Replies

  • allanallan Posts: 65,352Questions: 1Answers: 10,842 Site admin

    Hi,

    Many thanks for the test case.

    I'm going to have to mull this over a bit - I'm afraid I don't have an immediate fix, but I do have a couple of ideas. For example I could do the string length calculation without the HTML, but then include the HTML for the longest string.

    Once (way back around v1.5) I used the DOM to get the exact width of the data, and that was pixel perfect, but holly molly it was slow! It had to be dropped and a "best effort" used instead (trading accuracy for performance). I've still got some work to get this right apparently...!

    Allan

  • palkittpalkitt Posts: 5Questions: 1Answers: 0

    I see this is tricky to balance performance and accuracy :-). Yes as you suggest, for the strings selecting the strings based on the length, and then use the full HTML for the selected (3) strings will work well I guess (as was done in 2.3.4).

    For the substrings, it is obviously more difficult. Is there a way to get the styling used for the particular substring and insert it into the temp table using that style?

    It will not be perfect, but an improvement to 2.3.4 which can be good enough?

    By the way, in my real application I had something like <span>&#10072;60&#10072;<\span> for the "age-column" which also turns out to work well in 2.3.4 (triggering on the "<"-character).

  • hodoninskahodoninska Posts: 13Questions: 2Answers: 0

    I have encountered some issues with the way column widths are being calculated after a recent upgrade from a version of DataTables that was about 3-years old.
    Perhaps there could be an option added to the column definitions whereby the level of accuracy vs performance is defined. If we have a column where we are willing to trade some performance in order to get the width calculated more accurately we could specify that.
    Alternatively could the text to be used to calculate the width be provided separately from the text to be displayed (i.e. the raw text instead of some html).
    Or perhaps the width could somehow be included with the data. I have no idea how this would be implemented in the API, but I could imagine how the system I support, which has a couple of text columns of very varied lengths, could determine what the longest value is and calculate a column width to be used for that dataset.

  • allanallan Posts: 65,352Questions: 1Answers: 10,842 Site admin

    @hodoninsk I'd welcome a link to your page or an link to a test case showing what you are seeing so I can incorporate it into my testing for the auto column width calculations.

    Allan

Sign In or Register to comment.