Skip to content

Commit

Permalink
Fix: responsive-display was incorrectly firing for all rows when ch…
Browse files Browse the repository at this point in the history
…anging page

Fix: When resizing the window the modal would update to show the information for the last row on the page, regardless of what row details should have been shown
  • Loading branch information
AllanJard committed Mar 17, 2023
1 parent 2fc2438 commit 80db80b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
19 changes: 13 additions & 6 deletions js/dataTables.responsive.js
Expand Up @@ -681,7 +681,7 @@ $.extend( Responsive.prototype, {
}
);

if ( res === true || res === false ) {
if ( typeof res === 'boolean' ) {
event(res);
}
}
Expand Down Expand Up @@ -833,8 +833,6 @@ $.extend( Responsive.prototype, {
var dt = this.s.dt;

dt.rows( {page: 'current'} ).iterator( 'row', function ( settings, idx ) {
var row = dt.row( idx );

that._detailsDisplay( dt.row( idx ), true );
} );
},
Expand Down Expand Up @@ -1216,6 +1214,7 @@ Responsive.display = {
var modal = $('<div class="dtr-modal"/>')
.append( $('<div class="dtr-modal-display"/>')
.append( $('<div class="dtr-modal-content"/>')
.data('dtr-row-idx', row.index())
.append( render() )
)
.append( $('<div class="dtr-modal-close">&times;</div>' )
Expand All @@ -1240,9 +1239,17 @@ Responsive.display = {
} );
}
else {
$('div.dtr-modal-content')
.empty()
.append( render() );
var modal = $('div.dtr-modal-content');

if (modal.length && row.index() === modal.data('dtr-row-idx')) {
modal
.empty()
.append( render() );
}
else {
// Modal not shown, nothing to update
return null;
}
}

if ( options && options.header ) {
Expand Down
12 changes: 12 additions & 0 deletions js/responsive.bootstrap.js
Expand Up @@ -39,10 +39,22 @@ _display.modal = function ( options ) {
.append( render() );

_modal
.data('dtr-row-idx', row.index())
.one('hidden.bs.modal', closeCallback)
.appendTo( 'body' )
.modal();
}
else {
if ( $.contains(document, _modal[0]) && row.index() === _modal.data('dtr-row-idx') ) {
_modal.find( 'div.modal-body' )
.empty()
.append( render() );
}
else {
// Modal not shown - do nothing
return null;
}
}

return true;
}
Expand Down
12 changes: 12 additions & 0 deletions js/responsive.bootstrap4.js
Expand Up @@ -39,10 +39,22 @@ _display.modal = function ( options ) {
.append( render() );

_modal
.data('dtr-row-idx', row.index())
.one('hidden.bs.modal', closeCallback)
.appendTo( 'body' )
.modal();
}
else {
if ( $.contains(document, _modal[0]) && row.index() === _modal.data('dtr-row-idx') ) {
_modal.find( 'div.modal-body' )
.empty()
.append( render() );
}
else {
// Modal not shown - do nothing
return null;
}
}

return true;
}
Expand Down
12 changes: 12 additions & 0 deletions js/responsive.bootstrap5.js
Expand Up @@ -53,12 +53,24 @@ _display.modal = function ( options ) {
.append( render() );

_modal
.data('dtr-row-idx', row.index())
.one('hidden.bs.modal', closeCallback)
.appendTo( 'body' )
.modal();

modal.show();
}
else {
if ( $.contains(document, _modal[0]) && row.index() === _modal.data('dtr-row-idx') ) {
_modal.find( 'div.modal-body' )
.empty()
.append( render() );
}
else {
// Modal not shown for this row - do nothing
return null;
}
}

return true;
}
Expand Down
12 changes: 12 additions & 0 deletions js/responsive.bulma.js
Expand Up @@ -34,6 +34,7 @@ _display.modal = function ( options ) {
.append( render() );

_modal
.data('dtr-row-idx', row.index())
.appendTo( 'body' );

_modal.addClass('is-active is-clipped');
Expand All @@ -47,6 +48,17 @@ _display.modal = function ( options ) {
closeCallback();
});
}
else {
if ( $.contains(document, _modal[0]) && row.index() === _modal.data('dtr-row-idx') ) {
_modal.find( 'div.modal-body' )
.empty()
.append( render() );
}
else {
// Modal not shown - do nothing
return null;
}
}

return true;
};
Expand Down

0 comments on commit 80db80b

Please sign in to comment.