Skip to content

Commit

Permalink
Fix: Column widths were not being correctly cleared from the floating…
Browse files Browse the repository at this point in the history
… element (due to the use of `min-width`) which resulting in poor layout

Fix: Unsize needs to be called when the loading element is removed from the DOM
Fix: Resize the header/footer when the DataTables `column-sizing` event is triggered

- Three individual bugs which were all visible if we used Bootstrap with
  FixedHeader and Responsive - new example added for that
  • Loading branch information
Allan Jardine committed Feb 5, 2016
1 parent 0a33797 commit e9e4a93
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
25 changes: 25 additions & 0 deletions examples/integration/responsive-bootstrap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dt-example table-type="html" table-class="display nowrap" order="2" framework="bootstrap">

<css lib="datatables fixedheader responsive" />
<js lib="jquery datatables fixedheader responsive">
<![CDATA[
$(document).ready(function() {
var table = $('#example').DataTable( {
responsive: true
} );
new $.fn.dataTable.FixedHeader( table );
} );
]]>
</js>

<title lib="FixedHeader">Responsive integration (Bootstrap)</title>

<info><![CDATA[
FixedHeader will automatically work with the [Responsive](https://datatables.net/extensions/responsive) extension for DataTables. All you need to do is enable both options on the table and they will automatically cooperate.
]]></info>

</dt-example>
17 changes: 14 additions & 3 deletions js/dataTables.fixedHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ $.extend( FixedHeader.prototype, {
that.update();
} );

dt.on( 'column-reorder.dt.dtfc column-visibility.dt.dtfc draw.dt.dtfc', function () {
dt.on( 'column-reorder.dt.dtfc column-visibility.dt.dtfc draw.dt.dtfc column-sizing.dt.dtfc', function () {
that.update();
} );

Expand Down Expand Up @@ -263,11 +263,13 @@ $.extend( FixedHeader.prototype, {
else {
if ( itemDom.floating ) {
itemDom.placeholder.remove();
this._unsize( item );
itemDom.floating.children().detach();
itemDom.floating.remove();
}

itemDom.floating = $( dt.table().node().cloneNode( false ) )
.css( 'table-layout', 'fixed' )
.removeAttr( 'id' )
.append( itemElement )
.appendTo( 'body' );
Expand Down Expand Up @@ -302,7 +304,10 @@ $.extend( FixedHeader.prototype, {

var set = function ( name, toWidths ) {
$(name, to).each( function ( i ) {
$(this).width( toWidths[i] ).css("min-width", toWidths[i] );
$(this).css( {
width: toWidths[i],
minWidth: toWidths[i]
} );
} );
};

Expand All @@ -326,7 +331,13 @@ $.extend( FixedHeader.prototype, {
var el = this.dom[ item ].floating;

if ( el && (item === 'footer' || (item === 'header' && ! this.s.autoWidth)) ) {
$('th, td', el).css( 'width', '' );
$('th, td', el).css( {
width: '',
minWidth: ''
} );
}
else if ( el && item === 'header' ) {
$('th, td', el).css( 'min-width', '' );
}
},

Expand Down

0 comments on commit e9e4a93

Please sign in to comment.