数据表设置默认选项
Datatables setting default options
这就是初始化dataTable 的方法
$('#example').dataTable( {
"columnDefs": [ {
"targets": 0,
"searchable": false
} ]
} );
我能做下面这样的事情吗?
var mytable = $('#example').dataTable();
mytable.columnDefs({
"columnDefs": [ {
"targets": 0,
"searchable": false
} ]
} );
这是因为我想在一个js文件中定义一个默认初始化,我在需要dataTables的页面中包含了这个文件,但仍然可以修改一些选项,以便能够自定义每页的一些内容。
我能看到的一种可能的方法是:
将数据表的初始化替换为:
var mytable;
function initialiseSpecificDatatable(options) {
mytable = $('#example').dataTable(options);
return mytable; // Return table so locally you can use it
}
然后,无论您在哪里指定/更改选项
var table = initialiseSpecificDatatable({
"columnDefs": [{
"targets": 0,
"searchable": false
}]
});
如果要重新创建表,您可能需要将.destroy()
添加到创建函数中。要做到这一点,只需添加:
try {
$(mytable).DataTable().destroy(); //Note capital D to return a DataTable API (See API docs)
} catch (e) {
// Fails if the table was not a DataTable at the time
}
在initialiseSpecificDatatable
功能开始时。
这是我在设置默认值时发现的,并将用作我的问题的解决方案。(检查用于合并对象内容的jquery扩展的使用情况)
// Disable search and ordering by default
$.extend( $.fn.dataTable.defaults, {
searching: false,
ordering: false
} );
// For this specific table we are going to enable searching except on first (0th) column
// (ordering is still disabled)
$('#example').DataTable( {
searching: true,
columnDefs: [{
"targets": 0,
"searchable": false
}]
} );
感谢
相关文章:
- CKeditor:更改对话框中的默认选择选项
- 如何从外部页面激活非默认引导选项卡
- AngularJS ng选项在选择一个选项后删除了默认的空白值
- 或者在表单上选择默认选项文本(选择1)
- Angularjs-设置不带ng选项的select的默认值
- 在AngularJS Dropdownlost中设置默认文本选项
- 使用jQuery向“选择选项”添加默认属性
- Angular:如何使用ngRepeat并设置默认单选按钮选项
- 选择非空选项后,默认选项消失
- 使用 ajax 填充选择时没有选定的默认选项的问题
- javascript中选项对象的默认值
- 我在angular JS中选择的默认选项
- 如何设置助手的默认(全局)选项
- 将默认选项添加到ng-if
- 默认按表列选择选项(使用Javascript)
- HTML选择:将默认值设置为给定值,而不是从选项列表中选择
- 如何在“挖空.js”中单击后显示选项默认标题
- 避免筛选异步 ng 选项默认值
- 显示所有选项的 ng 选项默认选项
- jQuery-插件选项默认扩展()