Skip to content

Footer misalignment when scrolling table #7578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amiart opened this issue Oct 25, 2024 · 2 comments
Closed

Footer misalignment when scrolling table #7578

amiart opened this issue Oct 25, 2024 · 2 comments
Labels
bootstrap3 Bug Issues which are marked as Bug

Comments

@amiart
Copy link
Contributor

amiart commented Oct 25, 2024

Bootstraptable version(s) affected

1.23.5

Description

Found 2 problems with footer position when scrolling table on Bootstrap 3.

  1. When moving horizontal scroll to end:

1

  1. When moving horizontal scroll to half and calling resetView():

2

Example(s)

<style>
.bootstrap-table .fixed-table-header {
    background-color: yellow;
}
.bootstrap-table .fixed-table-footer {
    background-color: yellow;
}
</style>

<button id="button" style="margin: 10px 0px">ResetView</button>

<div style="width: 500px;">
  <table id="table" data-striped="true" data-show-footer="true" data-height="260">
  </table>
</div>

<script>
  var $table = $('#table');
  var $button = $('#button');
  
  function footerFormatter(data) {
    return 'Footer ' + (this.field+1);
  }

  $(function() {
    $table.bootstrapTable({
      columns: [
        {
          field: 0,
          title: 'Header No.1',
          footerFormatter: footerFormatter
        }, {
          field: 1,
          title: 'Header No.2',
          footerFormatter: footerFormatter
        }, {
          field: 2,
          title: 'Header No.3',
          footerFormatter: footerFormatter
        }, {
          field: 3,
          title: 'Header No.4',
          footerFormatter: footerFormatter
        }, {
          field: 4,
          title: 'Header No.5',
          footerFormatter: footerFormatter
        }, {
          field: 5,
          title: 'Header No.6',
          footerFormatter: footerFormatter
        }, {
          field: 6,
          title: 'Header No.7',
          footerFormatter: footerFormatter
        }, {
          field: 7,
          title: 'Header No.8',
          footerFormatter: footerFormatter
        }
      ],
      data: [
        [10, 20, 30, 40, 50, 60, 70, 80],
        [100, 200, 300, 400, 500, 600, 700, 800],
        [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000],
      ]
    })
  
    $button.click(function() {
      $table.bootstrapTable('resetView');
    });
  })
</script>

Possible Solutions

To fix the second problem, add these lines at the end of horizontalScroll() function:

// Synchronize footer position with table body
if (this.options.showFooter && !this.options.cardView) {
    this.$tableFooter.scrollLeft(this.$tableBody.scrollLeft());
}

Additional Context

Windows 10
Chrome 130
Bootstrap 3

@amiart amiart added the Bug Issues which are marked as Bug label Oct 25, 2024
@wenzhixin
Copy link
Owner

This is a bug that only exists in Bootstrap 3. Since Bootstrap 3 is no longer being maintained, it is recommended to upgrade to Bootstrap 5. For Bootstrap 3, here is a temporary solution.

bootstrap-table-bootstrap3.js

const _resetView = BootstrapTable.prototype.resetView

BootstrapTable.prototype.resetView = function (params) {
  _resetView.apply(this, [params])
  setTimeout(() => {
    // only bootstrap3
    this.$tableBody.trigger('scroll')
  }, 100)
}

Working example: https://live.bootstrap-table.com/code/wenzhixin/18308

@objecttothis
Copy link

This is a bug that only exists in Bootstrap 3. Since Bootstrap 3 is no longer being maintained, it is recommended to upgrade to Bootstrap 5. For Bootstrap 3, here is a temporary solution.

bootstrap-table-bootstrap3.js

const _resetView = BootstrapTable.prototype.resetView

BootstrapTable.prototype.resetView = function (params) {
  _resetView.apply(this, [params])
  setTimeout(() => {
    // only bootstrap3
    this.$tableBody.trigger('scroll')
  }, 100)
}

Working example: https://live.bootstrap-table.com/code/wenzhixin/18308

@wenzhixin I don't think this is correct. You can see from screenshots I've posted on #7090 that the issue also exists on your demo site which, I assume, is using bootstrap 5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bootstrap3 Bug Issues which are marked as Bug
Projects
None yet
Development

No branches or pull requests

3 participants