layui表格高度不根据屏幕大小自适应问题

218 阅读1分钟
function loadTable(tableData) {
    instable = layui.table.render({
        even: true,
        page: true,
        title: '',
        elem: '#demo',
        page: {
            layout: ['prev', 'page', 'next', 'limit', 'count', 'skip']
            , first: false
            , last: false
            , prev: '上一页'
            , next: '下一页'
        },
        // height: '310',
        height: $("#id").parent().height() - 30,
        cols: [[
            , { field: 'id', title: 'id', hide: true, align: 'center' }
            , { field: 'value', title: '值', align: 'center' }
        ]],
        data: tableData
    });
}

// 监听窗口大小变化事件 
$(window).on('resize', function() { 
// 窗口大小发生变化时执行的操作 
updateTableHeight(); 
});
// 检测屏幕大小的函数 
function checkScreenSize() { 
var screenWidth = $(window).width(); 
var screenHeight = $(window).height(); 
// 打印当前屏幕宽度和高度 
console.log('屏幕宽度: ' + screenWidth + 'px'); 
console.log('屏幕高度: ' + screenHeight + 'px'); 
// 在这里可以添加其他操作,比如根据屏幕大小调整布局等 }
}
function updateTableHeight() {
    var newHeight = $("#id").parent().height() - 30;
    instable.reload({
        height: newHeight
    });
}