working fiddle with generated data
IT WORKS
by KevinGabbert
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Include DataTables CSS from CDN -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">
</head>
<body>
<div class="container mt-5">
<br>
<div id="table-container">
<!-- Placeholder for the table -->
</div>
</div>
<!-- Link jQuery and DataTables JS from CDN -->
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<!-- Your script section -->
<script type="text/javascript">
$(document).ready(function () {
// Fetch and populate grid on page load
fetchDataAndUpdateGrid();
});
function fetchDataAndUpdateGrid() {
// Generate fake data for demonstration
var fakeData = generateFakeData();
// Update the grid with fetched data
updateGrid(fakeData);
}
function updateGrid(data) {
$("#table-container").empty();
var table = $("<table>").attr("id", "example").addClass("display");
var thead = $("<thead>").append("<tr><th>Description</th><th>ProductCategory</th><th>LeadTime</th><th>MinInventoryLevel</th><th>MaxInventoryLevel</th><th>SalesHistory</th><th>LastPORUpdate</th><th>LastTIRun</th></tr>");
var tbody = $("<tbody>");
$.each(data, function (index, item) {
var row = $("<tr>").append(
$("<td>").text(item.Description),
$("<td>").text(item.ProductCategory),
$("<td>").text(item.LeadTime),
$("<td>").text(item.MinInventoryLevel),
$("<td>").text(item.MaxInventoryLevel),
$("<td>").text(item.SalesHistory),
...