📄 Documentation: Dynamic Table from JSON

This page documents the functionality of a dynamic HTML table that loads and formats data from an external JSON file using Bootstrap 5 for styling.

🔧 Overview

🧠 JSON Structure

The JSON file should contain two keys: headers and data.

{
  "headers": [
    { "key": "status", "label": "Status", "type": "badge", "class": "text-center", "tooltip": "Current status" },
    { "key": "amount", "label": "Amount", "type": "currency" }
  ],
  "data": [
    { "status": "Published", "amount": 1234.56 },
    { "status": "Error", "amount": 0 }
  ]
}

📦 Supported Types

Type Description Example Output
badgeBootstrap badge with contextual colorPublished
linkClickable hyperlinkhttps://example.com
currencyFormatted dollar amount$1,234.56
dateFormatted date stringAug 20, 2025
codeMonospaced code blockinit()
booleanTrue/false icon✅ / ❌
textPlain textHello World

📜 JavaScript Functions

formatCell(value, type)

Formats a cell based on its type.

renderTable(json)

Builds the table from the JSON object and injects it into the page.

fetch("jsonCode.json")

Loads the JSON file and calls renderTable().

🧩 Extending the Code

✅ Bootstrap Integration

Ensure Bootstrap 5 is loaded in the <head>:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">