Issue with column's width when server-side processing enabled

Issue with column's width when server-side processing enabled

ThibThib Posts: 51Questions: 2Answers: 0
edited January 2013 in General
Hi,

The behaviour is a bit strange : whenever I interact with the table (paging, sorting, ...), the column's width evolves, depending on the cell's content.

Is it a known issue ? Is there any workaround ?

Here are the debug data : http://debug.datatables.net/oroluq

Thanks !

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    It will change if the table can't show the new content in the same layout as the old layout. Exactly why that is will depend upon the content. Can you link to a test case?

    Allan
  • ThibThib Posts: 51Questions: 2Answers: 0
    I don't quite understand the layout thing :-)
    Do you mean there's nothing strange as Datatables cannot compute each column's max width (because of Data are still not loaded) ?

    For the test case, it will be a bit hard (web service that produces JSON and web application deployed locally). Maybe you have some JSON data available through the Internet so I could try to write a jsfiddle ?
  • ThibThib Posts: 51Questions: 2Answers: 0
    I just tested the Nigel's trick found here : http://datatables.net/forums/discussion/4885/column-width-not-refreshed-after-ajax-load./p1

    [code] ...
    "fnInitComplete": function() {
    this.fnAdjustColumnSizing(true);
    },
    [/code]

    and the columns resizing is much less ugly :-)

    But, I still don't understand why there is still some changes in the column's width (a few pixels only) when the table is redrawn (after paging for instance), whereas there remain lots of space in each columns. Any idea ?

    Thanks !
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Browser layout of tables is a dark art! The different content will be causing the realignment of the content, and that is decided but he browser - despite the fact that I've tried to set the width of the columns in DataTables. The browser can override that. The only way to get pixel perfect alignment is to use `table-layout: fixed` - and generally you don't want to do that!

    Allan
  • ThibThib Posts: 51Questions: 2Answers: 0
    Thanks Allan !

    So, using fnAdjustColumnSizing(true) in fnInitComplete seems to be the better solution.
    Is there any cons using it ? Maybe performance issues ?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Just a performance hit.

    To be honest, DataTables should perhaps do that automatically. I'll have a think about adding it in :-)

    Allan
  • ThibThib Posts: 51Questions: 2Answers: 0
    Thanks for the tip Allan !
    So I'll add it by default when server-side processing is enabled :-)

    Regards,
    Thibault.
This discussion has been closed.