这是我的Angular 4组件类
@Component({
selector: 'food-list',
templateUrl: 'foodList.component.html'
})
export class FoodListComponent implements OnInit {
searchFoodForm: FormGroup;
Food_foodName_eq: FormControl;
Food_rating_eq: FormControl;
Food_restaurants_restName_eq: FormControl;
columns: object[] = [
{data: 'id', title: 'Id'},
{data: '11', title: 'rating'},
{data: 'description', title: 'Description'},
{data: 'foodName', title: 'Food Name', width: 200},
{data: '<button (click)= 'editFood(1)'> Edit <button>', title: 'edit',
renderer: 'html'},
];
instance: string = "hotInstance";
data = [];
constructor(private foodService: FoodService, private fb: FormBuilder,private _hotRegisterer: HotRegisterer) {
this.createSearchForm();
}
createSearchForm() {
this.searchFoodForm = this.fb.group({
Food_foodName_eq: '',
Food_rating_gt: '',
Food_restaurants_restName_eq:''
});
}
searchFood() {
let searchParam = { "params": JSON.stringify(this.searchFoodForm.value) };
this.fetchData(searchParam);
}
fetchData(searchParam){
if(searchParam == "" || searchParam == undefined){
searchParam = {"params" : searchParam};
}
this.foodService.getAll(searchParam).subscribe(suc => {
let dataSchema = suc ;
this.data = dataSchema["data"];
this.columns = dataSchema["schema"];
},
err => {
console.log("Something is wrong");
})
}
ngOnInit() {
let searchParam = "";
this.fetchData(searchParam);
}
editFood(id:any){
alert("uuuu");
}
}
这是我的组件.html文件
<hot-table
height="250"
[columns]="columns"
[data]="data">
</hot-table>
数据出现在handsontable中。我在表格中有一个编辑按钮。当按下编辑按钮时,我想调用'editFood(id:any)'函数,但它没有触发。我将单元格呈现为HTML。如何将此事件与handsontable绑定?控制台中没有显示错误。如果我使用警报功能而不是editFood函数,则会触发该功能。
我应该使用自定义渲染器来创建按钮吗?