Datatables: Change height of table not working

前端 未结 3 777
孤城傲影
孤城傲影 2020-12-30 10:03

I am using a Jquery Datatables table with bPaginate = false and sScrollY is some fixed height. Ultimately I want the table to resize on the window.resize event.

To

3条回答
  •  轮回少年
    2020-12-30 10:25

    Ok what seems to work nicely is to do tap into the elements added by the datatbables framework:

    $(window).resize(function() {
      console.log($(window).height());
      $('.dataTables_scrollBody').css('height', ($(window).height() - 200));
    });
    
    $('#example').dataTable({
      "sScrollY": ($(window).height() - 200),
      "bPaginate": false,
      "bJQueryUI": true
    });
    

    This example lets the table resize smoothly with the window.

    Live example: http://jsbin.com/anegiw/18/edit

提交回复
热议问题