jQuery Datatables Header Misaligned With Vertical Scrolling

前端 未结 20 2599
北海茫月
北海茫月 2020-12-15 05:05

I\'ve posted this in the datatables.net forums, but after a week, still no response. Hopefully I can find help here...

I\'m using datatables version 1.8.1 and am ha

20条回答
  •  不知归路
    2020-12-15 05:19

    I found that the width would misalign in the first window scroll, so the solution is to, on the first scroll only request a new table draw.

    const $table = $('#table').DataTable({ ... });
    
    $(window).on('scroll', () => {
      $(window).off('scroll');
      $table.tables().draw();
    });
    

    Edit: Also works with a setTimeout function. This depends when the misaligning happens.

    $table.tables().draw() is the key here.

提交回复
热议问题