Table width when redrawing

Table width when redrawing

flarpyflarpy Posts: 47Questions: 0Answers: 0
edited November 2012 in General
Hi Allan

I now have a really great implementation of datatables which is doing nearly everything I need. One of the things it does is allow the user to add and remove columns dynamically. If the user selects a large number and gets a horizontal scrollbar that's fine. However, if they then remove columns the table stays the same width. I am calling fnDraw once done, here is the code. Can you let me know how to get the table to shrink to the correct width please?

[code]
var updateColumns = function ()
{
$('input.columnSelector[type=checkbox]').each(function (){
var iCol = findColumnNumber($(this).attr('id').substring(6, $(this).attr('id').length));
oTable.fnSetColumnVis( iCol, $(this).is(':checked'));
});
oTable.fnDraw();
}
[/code]

Replies

  • flarpyflarpy Posts: 47Questions: 0Answers: 0
    edited November 2012
    ...
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    As in to shrink with the columns as they are removed? That's actually not something DataTables has the ability to do at the moment I'm afraid. The complexity of the table width calculations lead me to make a simplifying assumption that the table would be 100% width of the container, and if scrolling is needed, then so be it - but the 100% width container still applies.

    The only way to alter this at the moment is to shrink the size of the container I'm afraid - and I suspect that is easier said than done since you need to know how much to shrink it by, which would require a table clone with the current content and no sizing applied.

    Column / table width is the bane of DataTables development! I can see why many other grid components choose to go with DIVs (although for me progressive enhancement wins every time :-) ).

    Allan
  • flarpyflarpy Posts: 47Questions: 0Answers: 0
    Ok, thanks. I'll post back any useful workarounds I come up with in case others can use. re: divs. If you go down that route I think column alignment would give you even more headaches!
This discussion has been closed.