在 EasyUI DataGrid 中,rowStyler 只能控制行內聯樣式(背景色、字體等),若需在特定欄位根據數據值顯示圖片(如星星評級),必須使用欄位的 formatter 函數。
formatter 屬性。value(欄位值)、row(整行數據)、index(行索引)。value 返回包含 <img> 標籤的 HTML 字串。columns: [[
{ field: 'level', title: '等級', width: 80,
formatter: function(value, row, index) {
if (value > 30) return '<img src="3.png" />';
if (value > 20) return '<img src="2.png" />';
if (value > 10) return '<img src="1.png" />';
return '';
}
}
]]
若同時需要行背景色與欄位圖片,rowStyler 處理整行樣式,formatter 處理特定欄位圖片,兩者互不干擾。
建議下載 EasyUI 中文 API 手冊,查閱 formatter、rowStyler、styler 等屬性的詳細用法。