首先,当使用最新的数据表v1.10.13和yadcf v0.9时,这是一个很棒的插件
嗨有问题,自动完成过滤只返回当前页面,
这是我的server_roccessing.php,
<?php
$requestData= $_REQUEST;
$columns = array(
0 => 'test01',
1 => 'test02',
2 => 'test03',
3 => 'test04',
4 => 'test05'
);
// getting total number records without any search
$sql = "SELECT id,test01,test01,test02,test03,test04, test05 ";
$sql.=" FROM sample";
$query=mysqli_query($mysqli, $sql) or die("server_processing.php: getData");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT id,test01,test01,test02,test03,test04, test05 ";
$sql.=" FROM sample WHERE 1 = 1";
// getting records as per search parameters
if( !empty($requestData['columns'][0]['search']['value']) ){ //name
$sql.=" AND test01 LIKE '".$requestData['columns'][0]['search']['value']."%' ";
}
if( !empty($requestData['columns'][1]['search']['value']) ){ //name
$sql.=" AND test02 LIKE '".$requestData['columns'][1]['search']['value']."%' ";
}
if( !empty($requestData['columns'][2]['search']['value']) ){ //name
$sql.=" AND test03 LIKE '".$requestData['columns'][2]['search']['value']."%' ";
}
if( !empty($requestData['columns'][3]['search']['value']) ){ //name
$sql.=" AND test04 LIKE '".$requestData['columns'][3]['search']['value']."%' ";
}
if( !empty($requestData['columns'][4]['search']['value']) ){ //name
$sql.=" AND test05 LIKE '".$requestData['columns'][4]['search']['value']."%' ";
}
$query=mysqli_query($mysqli, $sql) or die("server_processing.php: getData");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
if ($requestData['length'] > 0 ){
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
} else {
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." ";
}
$query=mysqli_query($mysqli, $sql) or die("server_processing.php: getData");
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["test01"];
$nestedData[] = $row["test02"];
$nestedData[] = $row["test03"];
$nestedData[] = $row["test04"];
$nestedData[] = $row["test05"];
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>
下面YADCF(0.9)与Datatables 1.10.13一起采取行动
var dataTable = $('#mygrid').DataTable( {
"serverSide": true,
"processing": true,
"ajax":{
url :"server_processing.php", // json datasource
type: "post", // method , by default get
}
});
yadcf.init(dataTable, [{
column_number: 0,
filter_type: "auto_complete"
}, {
column_number: 1,
filter_type: "multi_select",
select_type: "chosen"
}, {
column_number: 2,
filter_type: 'auto_complete'
}, {
column_number: 3,
filter_type: 'auto_complete'
}, {
column_number: 4,
filter_type: 'auto_complete'
}]);
基于文本工作过滤,如魅力,但是,当基于自动完成过滤时,它只返回当前页面..
TQ