rowname 陣列)perUnitWidth)addData() 動態更新資料、getData() 取得陣列資料、getHead() 取得表頭陣列<div id="testdiv" align="center"></div>
<script>
var grid = new LeftHeadGrid({
id: 'leftHeadGrid',
width: 800,
title: '資料表格標題',
perUnitWidth: 300, // 每單位寬度像素
rowHeads: [{ // 左側表頭定義
width: '60',
rowname: [
{name: '日期'},
{name: '數值'}
]
}],
columnDatas: [{ // 右側資料欄定義
width: [1, 1], // 相對單位,實際寬度 = 單位 * perUnitWidth
rows: [
[10130501, 101011],
[2, 3]
]
}]
});
grid.RenderTo('testdiv');
</script>
var LeftHeadGrid = function(config) {
this.rowHeads = config.rowHeads || [];
this.columnDatas = config.columnDatas || [];
this.width = config.width || '100%';
this.id = config.id || 'TreGrid';
this.perUnitWidth = config.perUnitWidth || 10;
this.title = config.title || '';
this.noDataStr = config.noDataStr || 'no data';
this.innerWidth = 0; this.innerLWidth = 0; this.height = 0;
};
LeftHeadGrid.prototype.createGrid = function() {
// 1. 產生左側固定表頭 Table HTML
// 遍歷 rowHeads → rowname,產生 ...
// 累加表頭總寬度 this.innerLWidth
// 計算資料區寬度 this.innerWidth = this.width - this.innerLWidth - 5
};
LeftHeadGrid.prototype.RenderTo = function(divId) {
// 組合外框 HTML:標題列 + 左側表頭區 + 右側資料區 (含捲動容器)
// 寫入目標容器 innerHTML
this.show(); // 渲染資料
};
LeftHeadGrid.prototype.show = function() {
// 根據 columnDatas[0] 產生右側資料 Table
// 計算各欄實際寬度 (width[i] * perUnitWidth)
// 若總寬度 < 容器寬度,壓縮容器寬度避免多餘空白
// 注入 #leftgriddataview innerHTML
};
LeftHeadGrid.prototype.addData = function(newData) {
this.columnDatas = newData;
this.show();
};
LeftHeadGrid.prototype.getData = function() {
// 回傳陣列:每列為逗號分隔字串
};
LeftHeadGrid.prototype.getHead = function() {
// 回傳表頭陣列
};
.outframecss { position: relative; border: 1px solid #ccc; font-family: 微軟正黑體; }
.grittitle { background: #f0f0f0; border-bottom: 1px solid #ccc; line-height: 30px; padding-left: 10px; }
.leftheadcss { position: absolute; left: 0; top: 30px; bottom: 0; overflow: hidden; background: #fff; z-index: 10; border-right: 1px solid #ccc; }
.leftheadcss table { border-collapse: collapse; width: 100%; }
.bluefirst, .bluelast { border: 1px solid #ccc; padding: 5px; background: #e8f0fe; color: #333; }
.bluelast { border-bottom: 2px solid #0066cc; } /* 最後一列加粗底線 */
.dataframecss { position: absolute; left: [表頭寬度]px; top: 30px; right: 0; bottom: 0; overflow: auto; }
.innerdivcss { min-height: 100%; }
class LeftHeadGrid ES6 語法,模組化導出。position: sticky 實現左側固定 (CSS 原生),僅需 .leftheadcss { position: sticky; left: 0; },無需計算 absolute 位置。DocumentFragment 或虛擬列表 (大量資料時)。RowHeadConfig, ColumnDataConfig, GridOptions。LeftHeadGrid 以「左側固定表頭 + 右側捲動資料區」解決寬表格瀏覽痛點。核心在於兩個獨立容器 absolute 定位同步滾動 (或現代 sticky)、動態計算欄寬、資料與表頭分離渲染。適合報表、試算表類介面。