Added RowClass option to toggle showing each dataset row as individual col-xx-xx Bootstrap classes (for datasets that return few results but large number of columns)

This commit is contained in:
Conner Harkness 2025-09-03 14:24:19 -06:00
parent 54d145e30d
commit 50bf5bead3

View File

@ -214,7 +214,7 @@
<?php if ($varRows !== null && count($varRows) > 0): ?> <?php if ($varRows !== null && count($varRows) > 0): ?>
<a class="nav-item btn btn-outline-light me-2" onclick="fnShowPage('#page-output');"><i class="fa fa-fw fa-table"></i> <span class="d-none d-lg-inline">Results</span></a> <a class="nav-item btn btn-outline-light me-2" onclick="fnShowPage('#page-output');"><i class="fa fa-fw fa-table"></i> <span class="d-none d-lg-inline">Results</span></a>
<a class="nav-item btn btn-outline-light me-2" onclick="fnExport();"><i class="fa fa-fw fa-download"></i> <span class="d-none d-lg-inline">.csv</span></a> <a class="nav-item btn btn-outline-light me-2" onclick="fnExport();" id="export-csv-button"><i class="fa fa-fw fa-download"></i> <span class="d-none d-lg-inline">.csv</span></a>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
@ -301,24 +301,24 @@
if (strlen($varInputs[5][$i]) > 0) if (strlen($varInputs[5][$i]) > 0)
$strInputDefaultValue = $varInputs[5][$i]; $strInputDefaultValue = $varInputs[5][$i];
$varOptions = []; $varInputOptions = [];
if (strtolower($varInputs[4][$i]) == "options") if (strtolower($varInputs[4][$i]) == "options")
{ {
$strOptionsList = $varInputs[5][$i]; $strOptionsList = $varInputs[5][$i];
$varOptions = explode(",", $strOptionsList); $varInputOptions = explode(",", $strOptionsList);
} }
?> ?>
<div class="mb-3"> <div class="mb-3">
<label><?= $strInputName; ?> <code><?= $strInputType; ?></code></label> <label><?= $strInputName; ?> <code><?= $strInputType; ?></code></label>
<?php if (count($varOptions) > 0): ?> <?php if (count($varInputOptions) > 0): ?>
<div class="input-group"> <div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-at"></i></span> <span class="input-group-text"><i class="fa fa-fw fa-at"></i></span>
<select class="form-select" name="<?= $strInputName; ?>"> <select class="form-select" name="<?= $strInputName; ?>">
<?php foreach ($varOptions as $o): ?> <?php foreach ($varInputOptions as $o): ?>
<?php <?php
$strLabel = $o; $strLabel = $o;
$strValue = $o; $strValue = $o;
@ -413,6 +413,11 @@
foreach ($varRow1 as $k => $v) foreach ($varRow1 as $k => $v)
$varColumns[] = $k; $varColumns[] = $k;
$strRowClass = null;
if (array_key_exists("rowclass", $varOptions))
if (preg_match("/^col\-/i", $varOptions["rowclass"]))
$strRowClass = $varOptions["rowclass"];
?> ?>
<div class="d-none d-print-block"> <div class="d-none d-print-block">
@ -438,62 +443,112 @@
</div> </div>
</div> </div>
<div class="table-responsive"> <?php if ($strRowClass !== null): ?>
<table class="table table-sm table-striped table-bordered w-100" id="table">
<thead class="sticky-top">
<tr>
<?php foreach ($varColumns as $col): ?>
<?php
// Hide columns that begin with underscore:
if ($col[0] == "_")
continue;
?>
<th class="text-nowrap sorting"><?= $col; ?> <?php DataTable::sortIcon(); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody> <div class="container-fluid">
<div class="row my-3">
<?php foreach ($varRows as $r): ?> <?php foreach ($varRows as $r): ?>
<?php <div class="<?= $strRowClass; ?>">
// Allow SQL data to control row classes with _row_class column:
$strRowClass = "";
if (array_key_exists("_row_class", $r))
$strRowClass = $r["_row_class"];
$strNextCellClass = ""; <table class="table table-sm table-striped table-bordered">
?>
<thead>
<tr>
<th class="bg-black text-white"><?= $varColumns[0]; ?></th>
<th class="bg-black text-white"><?= $r[$varColumns[0]]; ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($varColumns as $col): ?>
<?php
// Hide columns that begin with underscore:
if ($col[0] == "_")
continue;
?>
<tr>
<td><?= $col; ?></td>
<td><?= $r[$col]; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>
</div>
</div>
<script>
$(function() {
$("#export-csv-button")
.first()
.addClass("d-none");
});
</script>
<?php else: ?>
<div class="table-responsive">
<table class="table table-sm table-striped table-bordered w-100" id="table">
<thead class="sticky-top">
<tr> <tr>
<?php foreach ($varColumns as $col): ?> <?php foreach ($varColumns as $col): ?>
<?php <?php
$strCellClass = "";
if (strlen($strRowClass) > 0)
$strCellClass = $strRowClass;
if (strlen($strNextCellClass) > 0)
$strCellClass = $strNextCellClass;
// Allow SQL data to controll next cell class with _next_cell_class column:
if (preg_match("/^_next_cell_class/i", $col))
$strNextCellClass = $r[$col];
// Hide columns that begin with underscore: // Hide columns that begin with underscore:
if ($col[0] == "_") if ($col[0] == "_")
continue; continue;
?> ?>
<th class="text-nowrap sorting"><?= $col; ?> <?php DataTable::sortIcon(); ?></th>
<td class="<?= $strCellClass; ?>"><?= $r[$col]; ?></td>
<?php
$strNextCellClass = "";
?>
<?php endforeach; ?> <?php endforeach; ?>
</tr> </tr>
<?php endforeach; ?> </thead>
</tbody>
</table> <tbody>
</div> <?php foreach ($varRows as $r): ?>
<?php
// Allow SQL data to control row classes with _row_class column:
$strRowClass = "";
if (array_key_exists("_row_class", $r))
$strRowClass = $r["_row_class"];
$strNextCellClass = "";
?>
<tr>
<?php foreach ($varColumns as $col): ?>
<?php
$strCellClass = "";
if (strlen($strRowClass) > 0)
$strCellClass = $strRowClass;
if (strlen($strNextCellClass) > 0)
$strCellClass = $strNextCellClass;
// Allow SQL data to controll next cell class with _next_cell_class column:
if (preg_match("/^_next_cell_class/i", $col))
$strNextCellClass = $r[$col];
// Hide columns that begin with underscore:
if ($col[0] == "_")
continue;
?>
<td class="<?= $strCellClass; ?>"><?= $r[$col]; ?></td>
<?php
$strNextCellClass = "";
?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php endif; ?> <?php endif; ?>
</div> </div>