This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
<?= $this->extend('layout/main_layout') ?>
|
||||
<?= $this->section('styles') ?>
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.10/css/jquery.dataTables.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.10/css/dataTables.bootstrap5.min.css">
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<style>
|
||||
@@ -131,10 +135,6 @@
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="9" class="text-center">No students found in this class.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -154,17 +154,33 @@
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<?= $this->section('scripts') ?>
|
||||
<script src="https://cdn.datatables.net/1.13.10/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.10/js/dataTables.bootstrap5.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
if (!(window.jQuery && jQuery.fn && jQuery.fn.DataTable)) {
|
||||
return;
|
||||
}
|
||||
<?php if (!empty($classes)): ?>
|
||||
<?php foreach ($classes as $index => $class): ?>
|
||||
$('#classTable<?= $index ?>').DataTable({
|
||||
const table<?= $index ?> = $('#classTable<?= $index ?>');
|
||||
const expectedColumns<?= $index ?> = table<?= $index ?>.find('thead th').length;
|
||||
const hasInvalidRows<?= $index ?> = table<?= $index ?>.find('tbody tr').toArray().some(function(row) {
|
||||
return $(row).children('td, th').length !== expectedColumns<?= $index ?>;
|
||||
});
|
||||
if (hasInvalidRows<?= $index ?>) {
|
||||
return;
|
||||
}
|
||||
table<?= $index ?>.DataTable({
|
||||
// Keep columns visible and avoid squeezing
|
||||
responsive: false, // prevent column hiding that can make table look small
|
||||
autoWidth: true, // let DT calculate widths, we'll still force 100% via CSS
|
||||
scrollX: true, // allow horizontal scroll when needed
|
||||
pageLength: 25,
|
||||
lengthChange: false,
|
||||
language: {
|
||||
emptyTable: 'No students found in this class.'
|
||||
},
|
||||
columnDefs: [
|
||||
{ targets: '_all', className: 'text-nowrap' } // avoid wrapping labels
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user