can i mix different types of sWidth (like px and %) ?

can i mix different types of sWidth (like px and %) ?

max4evermax4ever Posts: 45Questions: 0Answers: 0
edited October 2011 in General
i want to have some columns with fixed width, and the rest of them to divide the free space in %

[code]
{ "sName": "ragsoc_denom", "sWidth": "50%"},
{ "sName": "piva", "sWidth": "80px"},
{ "sName": "telefono", "sWidth": "25%"},
{ "sName": "indirizzo", "sWidth": "25%"},
{ "sName": "cap", "sWidth": "50px"},
{ "sName": "citta", "sWidth": "50px"},
{ "sName": "id", "sWidth": "70px"};
[/code]
however the columns with PX width, get a width less than the one specified resulting in the ordering icon arrows under the text and ugly formattation

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Yes you can - however, are you certain that 50% + 80px + 2*(25%) + 2*(50px) + 70px == 100%? The browser will try to reflow the table a bit if this calculation isn't absolutely correct (including margins, borders and padding). It can be very difficult to get exact width control in a table - you need to be careful with the numbers :-).

    Also one thing worth noting is that DataTables will convert your % values to pixels when the draw occurs (it will build a "worst case" table and apply your sizing, then read back the pixel values calculated, so that the table doesn't jump around all over the place when paging.

    Allan
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    how could i apply my own calculation, something like
    [code]
    var free_space = ($('#table').width() - $('#fixed_width_th_cell').width());
    $('#percentual_width_cell_th').width(free_space/3);
    [/code]
    and where should i run it in ? fnDrawCallback?

    i noticed that if i only specify the pixel sWidth and don't specify the percentual sWidth, the % td split the space evenly beetween them but i can't decide how much of it
This discussion has been closed.