datatables broken
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">
<style>
/* Add border style */
#partsTable {
border: 1px solid #dee2e6;
}
</style>
</head>
<body>
<div class="container mt-5">
<br>
<div id="PartsTableSection">
<div id="table-container" class="display">
<!-- Placeholder for the table -->
</div>
</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">
// Fetch and populate grid on page load
$(document).ready(function () {
// Fetch and populate grid on page load
fetchDataAndUpdateGrid();
});
function fetchDataAndUpdateGrid() {
// Generate fake data for demonstration
var fakeData = generateFakeData("Vendor", "Category");
// Update the grid with fetched data
updateGrid(fakeData);
}
function updateGrid(data) {
// Remove existing table before updating
$("#table-container").empty();
var table = $("<table>").attr("id", "partsTable").addClass("table table-hover");
var tbody = $("<tbody>");
// Column titles
var columnTitles = ["Description", "Product Category", "Lead Time", "Min Inventory Level", "Max Inventory Level", "Sales History", "Last POR Update", "Last TIA Run"];
// Title row
var titleRow = $("<tr>").addClass("table-primary");
$.each(columnTitles, function (index, title) {
...