Empty Table adding a Row: Column Width=0

Empty Table adding a Row: Column Width=0

akreiderakreider Posts: 33Questions: 0Answers: 0
edited November 2009 in General
I have an empty table with a couple columns that have their width defined using .

When I add a row to the table, the width is defined as "style: width:0px;"

It looks like DataTables (1.5.2) has the width set automatically when the table is initialized, and then doesn't update it when a row is added.

Example of an empty table where this is a problem:


Person  &nbsp





If I have the same table and it starts off with a row of data then Datatables correctly defines the style:width as non-zero. For instance I have a table where I defined the columns to be 220 and 22, it reduces them to 210 and 20.

What can I do to fix this?

Replies

  • akreiderakreider Posts: 33Questions: 0Answers: 0
    This table is defined in javascript as:

    sub_people=$("#sub-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false,
    "aoColumns": [{"sType":"html"}, null, null, null],
    "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}, {"bSortable":false}] });
  • akreiderakreider Posts: 33Questions: 0Answers: 0
    Is there a recalculate column width function?

    (Otherwise I could add a hidden row, but that seems messy.)
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi akreider,

    In order to stop DataTables trying to be clever with with column widths, set bAutoWidth:false in the initialisation object. There currently is no re-calculate width method, but that's something that I'd like to look at including in a future release.

    With bAutoWidth:false, then the widths of the columns are left entirely to your control and DataTables won't try to get all smart and do what it thinks is "best" ;-). Therefore you can then use standard DOM methods to manipulate the column widths, or leave it to the browser to manipulate as it sees best.

    Regards,
    Allan
  • akreiderakreider Posts: 33Questions: 0Answers: 0
    Thanks. It worked!
This discussion has been closed.