Fixed column width management

Fixed column width management

leejoon88leejoon88 Posts: 2Questions: 0Answers: 0
edited May 2012 in Bug reports
Hello,

I'm currently using DataTables with Fixed Columns on my page. The first two columns are fixed to the left and the second one has values that range from 4 characters to 60-70 characters. I need the second fixed column width to be resize every redraw so that it will show the entire cell's contents. Any changes I make to aoColumnDefs, including at initialization, are not applied. I believe this is because FixedColumns uses iLeftWidth.

Does anyone know if there is a way to change iLeftWidth of fixedcolumns after the initial load? Any reliable method to control the column widths would be nice.

[code]
var oTable = $('#product_list').dataTable( {
"fnInitComplete": function() {
new FixedColumns(oTable, {
"iLeftColumns": 2
});
});

$('#reset_all').click(function() {

/* whatever code here should change the iLeftWidth value accomodate the longest table cell in the fixed columns */
});
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You can use relative sizing with FixedColumns like in this example: http://datatables.net/release-datatables/extras/FixedColumns/scale_relative.html . However, there isn't currently a way to provide pixel perfect column control at the moment. I'm currently developing FixedColumns 2.5 which will help with that aspect a bit, but I suspect not in its entirety since ultimately it is down to how DataTables sizes the column and FixedColumns picks up on that - pixel perfect column sizing in DataTables is a fairly complex topic that I hope to explore in a blog post in the nearish future.

    Allan
  • leejoon88leejoon88 Posts: 2Questions: 0Answers: 0
    Relative sizing is percentage of the container still. I need some way to control width by its contents.

    All of the documentation calls FixedColumns right after datatables is defined with:
    [code]
    new FixedColumns( oTable );
    [/code]

    Is there no way to call this after initialization? I was hoping I could have sometime like

    [code]
    $('#resize_fixed_columns').click(function() {
    var oTable = $('body').data('oTable');
    FixedColumns(oTable, {
    "iLeftColumns":2,
    "iLeftWidth":500
    });
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You can call it any time you want, but only once and the DataTable must already exist. There isn't a method to set the column widths dynamically at the moment I'm afraid (this extends to DataTables as a whole in fact).

    Allan
This discussion has been closed.