【发布时间】:2016-05-04 10:07:42
【问题描述】:
我正在为 jQuery DataTable 编写一个小型自定义插件,它通过标准表级别选项启用。我有两个问题:
- 能够添加插件随后检索的自定义列定义选项
- 将标准 DataTable 列选项设置为在运行时确定的新值。
例如,我会这样定义我的表:
$('#example').DataTable( {
myPlugin: true,
columns: [
{
name: 'col1',
myPluginOption: ['optionVal1', 'optionVal2']
},
.
.
.
]
} );
然后在插件中,我想将一个侦听器附加到“dt.init”事件并在其中执行以下操作:
...
_dtInit: function() {
this.dt.columns().every(function() {
//1. retrieve the value of my custom option
var myOptions = this.myPluginOption; //or this.myPluginOption() ?
...
//2. set a default column option to a new value that
//wasn't known at initial definition (e.g.: dataOrder)
this.dataOrder = [newInt1, newInt2];
});
}
谢谢!
【问题讨论】: