控制器回傳正確 JSON(含 rows、total),DataGrid 初始化無報錯,但表格無資料,甚至表頭不顯示。
product_name)必須與 DataGrid columns 定義的 field 完全一致(區分大小寫)。{"total":1,"rows":[...]},確認無多餘巢狀或缺少 total。<jsp:include page="../fragments/BootStrapFiles.jsp"/> 是否引入衝突樣式。<table id="tt"></table> 若無寬高,DataGrid 可能無法渲染。建議在初始化時指定 width/height 或父容器有明確尺寸。// 1. 瀏覽器開發者工具 Network 面板確認回應 JSON 結構
// 2. Console 執行 $('#tt').datagrid('getData') 檢查內部資料
// 3. 暫時移除 Bootstrap 引用測試是否為樣式衝突
// 4. 簡化 columns 只保留一個欄位測試
$('#tt').datagrid({
url: '/store/saleout/getjson',
method: 'POST',
fitColumns: true,
singleSelect: true,
columns: [[
{field: 'product_name', title: '產品名稱', width: 100},
{field: 'numbers', title: '數量', width: 80, align: 'right'},
{field: 'price', title: '價格', width: 80, align: 'right'},
{field: 'buyer', title: '買方', width: 100}
]],
onLoadError: function() {
console.error('DataGrid 載入失敗');
}
});
table 樣式常覆蓋 EasyUI)。Content-Type 為 application/json; charset=utf-8。