lazurit/app/static/liquid/js/init_table.js

67 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
});
});