Empty Table adding a Row: Column Width=0
Empty Table adding a Row: Column Width=0
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  
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?
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  
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?
This discussion has been closed.
Replies
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}] });
(Otherwise I could add a hidden row, but that seems messy.)
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