您好,我一直在尝试获取行点击事件以与服务端Ajax调用一起使用。问题是我根本无法使rowCallback函数正常工作。有谁知道可能是什么问题?
我正在尝试将以下两个示例结合在一起。我认为这应该是一个简单的任务。我已经在网上搜索解决方案,但没有遇到其他遇到与我同样的问题的人。我目前是Angular的新手,所以我正在尝试学习如何创建Angular Web应用程序。
示例: http://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way http://l-lin.github.io/angular-datatables/#/advanced/row-click-event
someClickHandler(info) {
this.message = info.product;
}
ngOnInit() {
//other code
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 10,
responsive: true,
serverSide: true,
processing: true,
ajax: (dataTablesParameters: any, callback, settings) => {
this.http
.post<DataTablesResponse>(
'placeholder',
dataTablesParameters, httpOptions
).subscribe(resp => {
this.filteredData = resp.data;
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: [],
});
});
},
columns: [{ data: 'product' }, { data: 'name' }, { data: 'vendor' }],
rowCallback: (row: Node, data: any[] | Object, index: number) => {
const self = this;
// Unbind first in order to avoid any duplicate handler
// (see https://github.com/l-lin/angular-datatables/issues/87)
$('td', row).unbind('click');
$('td', row).bind('click', () => {
self.someClickHandler(data);
});
return row;
}
};
}