Generative-Dynamic-Table 1.0

by velo_ninja

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TempManager Modular Table</title>
<style>
  .table-wrapper {
    overflow: auto;
    max-height: 400px;
    border: 1px solid #000;
    position: relative;
  }

  table {
    border-collapse: collapse;
    width: max-content;
  }

  th, td {
    border: 1px solid #000;
    padding: 2px 5px;
    min-width: 80px;
    height: 30px;
    box-sizing: border-box;
  }

  /* Sticky top-left corner */
  th.corner {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 10;
    background: red;
    width: 80px;
    height: 30px;
  }

  th.sticky {
    position: sticky;
    top: 0;
    background: #eee;
    z-index: 5;
  }

  th.sticky-left, td.sticky-left {
    position: sticky;
    left: 0;
    background: #ddd;
    z-index: 4;
  }

  .control-section {
    margin: 5px 0;
  }

  textarea.json-preview {
    width: 100%;
    height: 150px;
  }
</style>
</head>
<body>

<div id="TempManager"></div>

<script>
const COMPONENTS = [
  { key: 'heads', label: 'Heads' },
  { key: 'extruders', label: 'Extruders' },
  { key: 'hotRunners', label: 'Hot Runners' },
  { key: 'flanges', label: 'Flanges' }
];

// --- EditableTable Class ---
class EditableTable {
  constructor(container, data) {
    this.container = container;
    this.data = data || [];
    this.renderTable();
  }

  renderTable() {
    if (!this.data.length) return;
    this.container.innerHTML = '';
    const wrapper = document.createElement('div');
    wrapper.className = 'table-wrapper';
    this.container.appendChild(wrapper);

    const table = document.createElement('table');
    wrapper.appendChild(table);

    // Determine headers
    const headers = typeof this.data[0] === 'object' && !Array.isArray(this.data[0])
      ? Object.keys(this.data[0])
      : Array.from({ length:...

CSS

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #929292;
  padding: 24px;
  color: #1c1e21;
}

#TempManager {
  max-width: 1600px;
  margin: 0 auto;
  background: #1c7bb7;
  padding: 32px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

#div_CompControls {
  background: #64d088;
  padding: 24px;
  border: 1px solid #000000;
  border-radius: 6px;
  margin-bottom: 24px;
}

.control-section {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.control-section:last-child {
  margin-bottom: 0;
}

.control-section span {
  font-size: 14px;
  font-weight: 600;
  color: #050505;
  min-width: 110px;
}

.control-section input[type="number"] {
  width: 70px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #ccd0d5;
  border-radius: 4px;
  font-size: 14px;
  text-align: center;
  background: #ffffff;
  color: #1c1e21;
  transition: all 0.2s ease;
}

.control-section input[type="number"]:hover {
  border-color: #b0b3b8;
}

.control-section input[type="number"]:focus {
  outline: none;
  border-color: #1877f2;
  box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.1);
}

.control-section button {
  min-width: 36px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid #ccd0d5;
  border-radius: 6px;
  background: #ffffff;
  color: #1c1e21;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.control-section button:hover {
  background: #f0f2f5;
  border-color: #b0b3b8;
}

.control-section button:active {
  background: #e4e6eb;
  transform: scale(0.96);
}

textarea {
  width: 100%;
  min-height: 130px;
  padding: 12px;
  border: 1px solid #ccd0d5;
 ...

JavaScript

[
  { "component": "heads_0", "zone_0": 200, "zone_1": 201 },
  { "component": "heads_1", "zone_0": 199, "zone_1": 202 },
  { "component": "extruders_0", "zone_0": 210, "zone_1": 211 },
  { "component": "extruders_1", "zone_0": 212, "zone_1": 213 },
  { "component": "flanges_0", "zone_0": 50, "zone_1": 51 },
  { "component": "hotRunners_0", "zone_0": 100, "zone_1": 102 }
]


[
  {"ID":1,"Name":"Item 1","Price":"23.45","InStock":"Yes","Category":"Cat 1","Rating":4},
  {"ID":2,"Name":"Item 2","Price":"67.89","InStock":"No","Category":"Cat 2","Rating":2},
  {"ID":3,"Name":"Item 3","Price":"12.34","InStock":"Yes","Category":"Cat 3","Rating":5}
]