一、ng2-handsontable
网址:https://valor-software.com/ng2-handsontable/
二、使用步骤
1.安装
npm i ng2-handsontable --save
2.引入module
import { HotTableModule } from 'ng2-handsontable';
...
@NgModule({
...
imports: [
HotTableModule
],
...
})
export class MyModule {
}
3.Use the hot-table component in your template
<hot-table [data]="data"
[columns]="columns"
[colHeaders]="colHeaders"
[colWidths]="colHeaders"
[options]="options"
(hotInstanceCreated)="init($event)"
(HANDSONTABLE_EVENT)="eventHandler">
</hot-table>
private data: any[] = getBasicData(10);
private colHeaders: string[] = ['ID', 'First Name', 'Last Name', 'Address',
'Favorite food', 'Price', 'Is active'];
private columns: any[] = [
{
data: 'id'
},
{
data: 'name.first',
renderer: 'text',
readOnly: true
},
{
data: 'name.last',
readOnly: true
},
{
data: 'address'
},
{
data: 'product.description',
renderer: 'text'
},
{
data: 'price',
type: 'numeric',
numericFormat: { pattern: '$0,0.00', culture: 'en-US' }
},
{
data: 'isActive',
type: 'checkbox',
checkedTemplate: 'Yes',
uncheckedTemplate: 'No'
}
];
private colWidths: number[] = [null, null, null, null, null, null, 30];
private options: any = {
stretchH: 'all',
columnSorting: true,
contextMenu: [
'row_above', 'row_below', 'remove_row'
]
};
private afterChange(e: any) {
// tslint:disable-next-line:no-console
console.log(e);
}
private afterOnCellMouseDown(e: any) {
// tslint:disable-next-line:no-console
console.log(e);
}