我不擅长javascript,我想知道如何使用PHP过滤输入和列过滤数据表中的列。
我只能按输入过滤。但是,我无法做到这两点。
这是我的输入服务器端过滤的工作代码。
HTML
<table id="example" class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>First Name</th>
<th>Last Name</th>
<th>Status</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>Username</th>
<th>First Name</th>
<th>Last Name</th>
<th>Status</th>
</tr>
</tfoot>
</table>
的jQuery
$(document).ready(function() {
$('#example tfoot th').each( function () {
var title = $('#example thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
});
var table = $('#example').DataTable({
"processing": true,
"serverSide": true,
"order": [
[0, 'desc']
],
"ajax": "server_processing.php"
});
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
});
});
});
PHP
<?php
// DB table to use
$table = 'test_table';
// Table's primary key
$primaryKey = 'id';
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'username', 'dt' => 1 ),
array( 'db' => 'firstname', 'dt' => 2 ),
array( 'db' => 'lastname', 'dt' => 3 ),
array(
'db' => 'status',
'dt' => '4',
'formatter' => function($d, $row) {
if($d == 1) {
return 'Success';
} else if($d == 2) {
return 'Pending';
} else {
return 'Fail';
}
}
),
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'testdb',
'host' => 'localhost'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( 'ssp.class.php' );
$result = SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns);
echo json_encode($result);
在datatable论坛中支持ssp.class.php。
提前多多感谢。请回答我的问题。