這次來介紹一個很棒的Table第三方套件 Handsontable ,其功能相當豐富像是編輯、排序、查詢、欄位驗證、匯出Excel等需求通通難不倒Handsontable,甚至可以直接將Excel的表格內容直接貼到Handsontable或者是將Handsontable的表格內容直接貼Excel,並且不會造成跑版和亂碼的問題。此外,前端三大主流框架(React、Angular、Vue)它都支援。 接下來,我們來簡單示範一下如何在Angular使用Handsontable。 1. 首先安裝Handsontable套件。 npm install @handsontable/angular handsontable 2. 在angular.json內匯入相關css。 "styles": [ "node_modules/handsontable/dist/handsontable.full.css", "src/styles.css" ] 3. 匯入Handsontable Module import { HotTableModule } from '@handsontable/angular'; @NgModule({ declarations: [ AppComponent ], imports: [ HotTableModule, ... ] }) export class AppModule { } 4. 使用hot-table元件且並設定settings,其常用屬性如下: colHeaders : 設定欄位的表頭名稱 data : 設定資料 dataSchema : 設定資料結構 columns : 可用於設定欄位的型別(text、autocomplete、dropdown、checkbox、password、date)、呈現方式(renderer)以及資料驗證(validator) ※客製化的呈現方式與資料驗證需要撰寫renderer callback 與validator callback 5. 如果需要對hot-table進行存取或是D...