[英]Reinitialize datatables with different script file
I have multiple datatables and created one js in where they have similar setup. 我有多个数据表,并在其中具有类似设置的地方创建了一个js。 I use the class of all tables instead each id of my tables. 我使用所有表的类而不是表的每个ID。
What doesnt work is if i want to create a specific jquery for each datatables where they have differences . 如果我想为每个有差异的数据表创建一个特定的jQuery,那是行不通的。 Some columns are needed not to be selected while others need to be . 有些列不需要选择,而另一些则需要。
So I used the Id for each table but it says cannot reinitialize. 因此,我为每个表使用了ID,但是它说无法重新初始化。 I also tried using bdestroy :true
but one is being disabled 我也尝试使用bdestroy :true
但其中之一被禁用
Here is my uniform script where i use the class : 这是我使用类的统一脚本:
<script type="text/javascript">
$(document).ready(function () {
$('.datatables').dataTable(
{
'initComplete': function(settings){
var api = new $.fn.dataTable.Api(settings);
api.columns().header().each(function(column){
if($(column).text() === 'Company'){
$(column).text("Apple");
}
if($(column).text() === 'Note'){
$(column).text("Description");
} }); },
"pagingType": "full_numbers",
"oSearch": {"bSmart": false},
dom: '<"coll"B><"search"f><"table"t><"info" i><"list"l><"pag"p>',
buttons: [{
extend: 'collection',
text: 'Esporti',
buttons: [ {
extend: 'excel',
text: 'Excel',
exportOptions: {
modifier: {
selected: true
}}},{
extend: 'pdf',
text: 'PDF',
exportOptions: {
modifier: {
selected: true
}}} ]}, ]
}); });
</script>
Here is the script for each page where i use the table id of each tables : 这是我使用每个表的表ID的每个页面的脚本:
<script>
$(document).ready(function () {
$('#circuiti_table').dataTable({
select: {
style: 'multi',
selector: ' tr>td:nth-child(4), tr>td:nth-child(5), tr>td:nth- child(6), tr>td:nth-child(7)'
} }); });
</script>
thanks in advance 提前致谢
Instead of using a combination of class name to specify common options and ID to specify unique options I would recommend a different approach. 我建议使用其他方法,而不是使用类名的组合来指定通用选项,而使用ID来指定唯一选项。
Use $.fn.dataTable.defaults
object to specify common options for all tables. 使用$.fn.dataTable.defaults
对象为所有表指定通用选项。 Then on each page, initialize a table using ID but only include options that are different. 然后在每个页面上,使用ID初始化表,但仅包含不同的选项。
For example: 例如:
// jQuery DataTables: Common settings
$.extend( true, $.fn.dataTable.defaults, {
"searching": false,
"ordering": false
} );
// jQuery DataTables: Individual table
$(document).ready(function() {
$('#example').DataTable();
} );
See Setting defaults for more information. 有关更多信息,请参见设置默认值 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.