最近我使用datatables和ignited-datatables库时遇到了问题。
我使用过datatables ver。 1.10.4和IgnitedDatatables ver。 2.0
似乎我不能像这个链接上提到的那样进行单独的列过滤:
https://datatables.net/examples/api/multi_filter.html
由于每次执行“keyup”时,表都会重新加载,但过滤条件不会绑定到数据中。无论如何通过使用chrome调试工具,我知道用于搜索的字符串已被发送到服务器:“columns [2] [search] [value]:some_string”,但不知何故服务器无法处理此字符串。
这是我的javascript代码:
table = $('#data_table').DataTable( {
'filter': true,
'processing': true,
'serverSide': true,
'ajax': {
'url' : '<?=site_url()?>/technician/get_data',
'type' : 'POST',
'data' : lar_data
},
'columns':[
{'data' : 'opt_edit', 'sortable' : false,'searchable' : false},
{'data' : 'opt_detail', 'sortable' : false, 'searchable' : false},
{'data' : 'TechnicianName'},
{'data' : 'TechnicianAddress'},
{'data' : 'TechnicianMobileNumber'},
{'data' : 'opt_delete', 'sortable' : false, 'searchable' : false}
],
'order' : [[2, 'asc']]
} );
table.columns().eq( 0 ).each( function ( colIdx ) {
$( 'input', table.column( colIdx ).footer() ).on( 'keyup', function () {
table
.columns( colIdx )
.search( this.value )
.draw();
} );
} );
模特:
function __construct()
{
parent::__construct();
$this->load->library('Datatables');
}
function get($filter)
{
$this->datatables->select('
TechnicianName,
TechnicianAddress,
TechnicianMobileNumber
');
$this->datatables->add_column(
'opt_edit',
'<a href="#">Edit</a>'
);
$this->datatables->add_column(
'opt_detail',
'<a href="#">Detail</a>'
);
$this->datatables->add_column(
'opt_delete',
'<a href="#"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>'
);
$this->datatables->from('ms_technician');
$this->datatables->where($filter);
return $this->datatables->generate();
}
查看:
<div class="table-responsive">
<table id="data_table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th width="1px"> </th>
<th width="1px"> </th>
<th>Name</th>
<th>Address</th>
<th>Mobile Phone</th>
<th width="1px"> </th>
</tr>
</thead>
<tfoot>
<tr>
<th width="1px"> </th>
<th width="1px"> </th>
<th>Name</th>
<th>Address</th>
<th>Mobile Phone</th>
<th width="1px"> </th>
</tr>
</tfoot>
<tbody></tbody>
</table>
</div>
有人可以帮我解决这个问题吗? 非常感谢你的帮助...