我的HTML如下所示。
<table id="address_datatable" class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th>Company Name</th>
<th>Contact Name</th>
<th>Email Address</th>
<th>Phone Number</th>
<th>Action</th>
</tr>
</thead>
<tbody>
我的jQuery代码如下所示
$(document).ready(function() {
$('#address_datatable').DataTable({
"columnDefs": [ {
"targets": [ 0, 2 ],
"orderable": false
} ]
});
});
2在"targets"
中工作,但0在工作。
我也尝试了以下示例。它不起作用
$('#example').dataTable( {
"columnDefs": [ {
"targets": 'nosort',
"orderable": false
} ]
} );
为什么会这样?
答案 0 :(得分:1)
尝试这种方式
以HTML
<table id="address_datatable" class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th>Company Name</th>
<th>Contact Name</th>
<th>Email Address</th>
<th>Phone Number</th>
<th class="nosort">Action</th>
</tr>
</thead>
<tbody>
在JS中
$('#address_datatable').dataTable( {
"columnDefs": [ {
"targets": 'nosort',
"orderable": false
} ]
} );
答案 1 :(得分:1)
请在您的问题中添加更多详细信息。 您正在使用ajax数据源还是简单的静态表数据?
如果ajax请执行以下操作。
ajax:{
type:'post', // whatever method
url:"your url"
},
"columns": [
//Specify your columns here
],
columnDefs:[
//Column definitions here
]
} );