-
-
Notifications
You must be signed in to change notification settings - Fork 425
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
Column width behaviour on 2 #283
Comments
Interesting one - thank you for posting this. I'm actually okay with the v2 behaviour there (and mildly surprised by the v1 behaviour, which I think is bug!). The key thing here is that when the DataTable is initialised there is a long string in it, and it correctly adjusts the column widths to show that. But then the DOM is updated without telling DataTables (important point - it doesn't listen for changes in the DOM), so it can't adjust. This is mentioned in the FAQs - although not directly about column widths. That is works in 1.x is testament to the fact that I've improved the column width handling in v2 funnily enough. If you inspect the header cell in v1 (without resizing the window, so you'd need the inspector already open) you'll see that there is a large assigned width, but that is mostly being ignored! I'm fairly sure there is a setTimeout for column widths in v1 somewhere as well which might be effecting it, although possibly that was for Ajax - can't recall! Either way, I'm comfortable that the v2 behaviour is actually okay. |
I'm inclined towards thinking that this "trick" needs to be properly "deprecated" on my side, since now export has orthogonal options and I can define directly in the renderer "display" vs "export" differently. At this point though I don't see the "or when the data changes significantly" bit in the documentation of columns.adjust()
Given that one may not have control on the renderer and something changes the DOM without telling Datatables, isn't "columns.adjust()" supposed to bridge "the gap", telling Datatables "hey, I'm sure something has changed, please (re)adjust based on the newly changed data " ? |
Ah yes, I think I see why v1 is resizing columns now. v2 caches the strings that it uses for the sizing table and needs a data invalidation (e.g. calling |
I'm perfectly fine with the performance optimization, but I guess the docs should reflect it, or for all intent and purposes "when the data changes significantly" columns.adjust() won't adjust ... anything !?
On top of that, if |
The expectation, as noted in the FAQs is that any change to the data should be through the DataTables API, and not through the DOM. Column widths aren't the only thing that would have problems with the data being changed without using the API. |
okay, then maybe just highlighting the FAQ in the context of |
Agreed! I'll add a note in. Thanks for flagging this up. |
np, have a nice day |
It seems that width calculation on version 2 doesn't take into account cells that change content (and may wildly change the width).
Documentation on columns.adjust() seems to permit this
I'm using something that could be definitely defined as a "trick" (but falls on the "when the data changes significally, IMHO) : rather than playing with orthogonal data, if I have a cell containing a link, I'd like "Copy" and "Export" buttons to have as the content the href of a link rather than the text representation of the link itself.
Till 1.13.x this worked:
<a href="https://somethingverylong" data-name="shortrepr">https://somethingverylong</a>
draw
call a function that swaps the content of the with "shortrepr"table.columns.adjust()
At this point, the user sees
<a href="somethingverylong" data-name="shortrepr">shortrepr</a>
, the cell is "short" (on 1.13.x), but on "copy" and "export" datatables exportshttps://somethingverylong
(because it strips html tags but fetches the original content of the cell)On 2.x, this still works, but the cell is "long": it seems to gather the length from the original content rather than the actual cell content.
I managed to reproduce a minimal case here (click on the "name" column to trigger a "draw")
Repro with 2.x https://live.datatables.net/laliruxi/1
Repro with 1.13.x https://live.datatables.net/yiroxoyu/1
The text was updated successfully, but these errors were encountered: