【发布时间】:2022-01-16 06:49:22
【问题描述】:
这是一个有趣的案例,当我使用纯 JS + jQuery 时,我实现了获取列数组的当前状态,但是当尝试在 Angular 12 中实现相同的事情时,这将不起作用! 我正在阅读 Angular 数据表的文档以及 datatables.net 但这对项目不起作用!
这是我试图在 Angular 中设置的代码:
import { Component, OnInit, ViewChild } from '@angular/core';
declare var $:JQueryStatic;
@Component({
selector: 'app-mandant',
templateUrl: './mandant.component.html',
styleUrls: ['./mandant.component.scss']
})
export class MandantComponent implements OnInit {
dtOptions = {};
constructor() { }
ngOnInit(): void {
this.dtOptions = {
dom: 'Bfrtip',
bLengthChange: true,
searching: false,
table: "#dttable",
info: true,
buttons: [
'colvis',
'copy',
'print',
'excel',
{
text: 'Some button',
key: '1',
action: function (e: any, dt: any, node: any, config: any) {
alert('Button activated');
}
}
],
colReorder: {
enable: true,
order: [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
}
};
this.dtOptions.on('column-reorder.dt', function (e, settings, details) {
console.log("You just reordered the cols, here is your current state: ", this.dtOptions.order());
});
}
ngAfterViewInit(): void {
}
}
对我来说的成就是这段代码,如果这段代码在每次更改列后返回数组的当前状态,我的担心就完成了:
this.dtOptions.on('column-reorder.dt', function (e, settings, details) {
console.log("You just reordered the cols, here is your current state: ", this.dtOptions.order());
});
【问题讨论】:
-
当你认为 dtoptions.on 方法被调用时?
-
问题是这个方法永远不会被调用!我希望在您发布专栏后立即调用它。
-
我想我已经找到了解决这个问题的办法。
-
@GRD 我全神贯注 :)
-
嘿@GRD 对不起,我找到了解决方案,但是如果我能帮助你,我会做的:)。告诉我你的情况!?
标签: javascript jquery angular datatables