Datatables on-the-fly resizing

后端 未结 12 2214
灰色年华
灰色年华 2020-12-12 16:21

I\'m using the marvellous DataTables jQuery plug-in; http://datatables.net/ Added the FixedColumns and KeyTable extras.

Now the table does resize prettily when the

12条回答
  •  青春惊慌失措
    2020-12-12 16:46

    I got this to work as follows:

    First ensure that in your dataTable definition your aoColumns array includes sWidth data expressed as a % not fixed pixels or ems. Then ensure you have set the bAutoWidth property to false Then add this little but of JS:

    update_table_size = function(a_datatable) {
      if (a_datatable == null) return;
      var dtb;
      if (typeof a_datatable === 'string') dtb = $(a_datatable)
      else dtb = a_datatable;
      if (dtb == null) return;
    
      dtb.css('width', dtb.parent().width());
      dtb.fnAdjustColumSizing();
    }
    
    $(window).resize(function() {
      setTimeout(function(){update_table_size(some_table_selector_or_table_ref)}, 250);
    });
    

    Works a treat and my table cells handle the white-space: wrap; CSS (which wasn't working without setting the sWidth, and was what led me to this question.)

提交回复
热议问题