67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
function getVisibleRowCount() {
|
||
const container = document.querySelector('#TableContainer');
|
||
const rect = container.getBoundingClientRect();
|
||
const containerHeight = rect.height;
|
||
|
||
const rowHeight = 60; // приблизительная высота строки таблицы
|
||
const tableContainer = document.querySelector('#Table').parentElement;
|
||
|
||
if (!tableContainer) return 5; // запас по умолчанию
|
||
|
||
const offset = 80; // запас на header
|
||
const availableHeight = containerHeight - offset;
|
||
|
||
return Math.max(1, Math.floor(availableHeight / rowHeight));
|
||
}
|
||
|
||
let tableInstance = null;
|
||
|
||
function initDataTable(rowCount) {
|
||
if (tableInstance) {
|
||
tableInstance.destroy();
|
||
}
|
||
|
||
tableInstance = $('#Table').DataTable({
|
||
responsive: true,
|
||
paging: true,
|
||
pageLength: rowCount,
|
||
searching: false,
|
||
lengthChange: false,
|
||
info: true,
|
||
ordering: false,
|
||
language: {
|
||
sProcessing: 'Подождите...',
|
||
sZeroRecords: 'Записи отсутствуют.',
|
||
paginate: {
|
||
first: "⏮",
|
||
previous: "←",
|
||
next: "→",
|
||
last: "⏭"
|
||
},
|
||
info: "Показано с _START_ по _END_ из _TOTAL_ записей",
|
||
infoEmpty: "Нет записей для отображения",
|
||
infoFiltered: "(отфильтровано из _MAX_ всех записей)"
|
||
}
|
||
});
|
||
}
|
||
|
||
function updateTableRowCount() {
|
||
const newRowCount = getVisibleRowCount();
|
||
initDataTable(newRowCount);
|
||
}
|
||
|
||
$(document).ready(function () {
|
||
updateTableRowCount();
|
||
|
||
// При изменении окна
|
||
$(window).on('resize', function () {
|
||
clearTimeout(window._tableResizeTimeout);
|
||
window._tableResizeTimeout = setTimeout(updateTableRowCount, 150);
|
||
});
|
||
|
||
// Отслеживаем вход и выход из полноэкранного режима
|
||
document.addEventListener('fullscreenchange', () => {
|
||
setTimeout(updateTableRowCount, 150);
|
||
});
|
||
});
|