How to dynamically change jQuery Datatables height

前端 未结 8 1877
情话喂你
情话喂你 2021-01-31 05:25

I\'m using jQuery Datatables. I want to change the height of the table whenever a user resizes the window. I\'m able to catch the window resize event which allows me to calculat

8条回答
  •  盖世英雄少女心
    2021-01-31 05:59

    Here is a simple solution as documented here

        $(document).ready(function() {
            $('#example').DataTable( {
                scrollY:        '50vh',
                scrollCollapse: true,
                paging:         false
            });
        });
    

    vh Relative to 1% of the height of the viewport*

    You can use the vh unit to set a height that varies based on the size of the window.

    Supported in: Chrome 20.0+, IE 9.0+, FireFox 19.0+, Safari 6.0+, Opera 20.0+

提交回复
热议问题