我尝试根据https://datatables.net/examples/api/multi_filter.html向表格中添加多个列过滤器 我正在使用服务器端选项。 一般搜索,分页和订购工作正常。 但是如果我在第一列中搜索字符串“teststring”,则ajax请求如下所示:
["sSearch_0"]=>
string(10) "teststring"
["sSearch_1"]=>
string(10) "teststring"
["sSearch_2"]=>
string(10) "teststring"
如果我在第2列中插入另一个字符串,则该字符串将发送到sSearch_0,sSearch_1和sSearch_2。 这种行为使我无法确定要过滤的列。 我的目标是在不同的列上搜索不同的值并获得ajax请求,如:
["sSearch_0"]=>
string(10) "value1"
["sSearch_1"]=>
string(10) "value2"
["sSearch_2"]=>
string(10) "value3"
这是我的表:
<table id="tabla" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Nombre</th>
<th>Expediente</th>
<th>Alcance</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Nombre</th>
<th>Expediente</th>
<th>Alcance</th>
</tr>
</tfoot>
</table>
这些是我的脚本
<!--Datatables load-->
<script>
$(document).ready(function() {
$('#tabla').dataTable( {
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"sAjaxSource": "server_side3.php?action=table_data",
"bDeferRender": true,
language: {
url: '//cdn.datatables.net/plug-ins/380cb78f450/i18n/Spanish.json'
}
} );
} );
</script>
<script>
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#tabla tfoot th').each( function () {
var title = $('#tabla thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Buscar '+title+'" />' );
} );
// DataTable
var table = $('#tabla').DataTable();
// Apply the search
table.columns().eq( 0 ).each( function ( colIdx ) {
$( 'input', table.column( colIdx ).footer() ).on( 'keyup change', function () {
table
.column( colIdx )
.search( this.value )
.draw();
} );
} );
} );
</script>
任何帮助将不胜感激。 圣塞瓦斯蒂安