【发布时间】:2016-08-31 16:03:38
【问题描述】:
YADCF 绑定到数据表,加载数据,但仅适用于文本和常规过滤器。 Range_number 无效,使用任何数字 - 未找到匹配记录。如果我禁用选项服务器端,一切都会像奇迹一样开始工作。请帮我。索引.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.css"/>
<link rel="stylesheet" type="text/css" href="https://yadcf-showcase.appspot.com/resources/css/jquery.dataTables.yadcf.css"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.js"></script>
<script type="text/javascript" src="https://yadcf-showcase.appspot.com/resources/js/jquery.dataTables.yadcf.js"></script>
<meta charset="utf-8">
<script>
$(document).ready(function() {
// Initialize DataTables
var table = $("#example").DataTable( {
"processing": true,
"serverSide": true,
"ajax": "serverSide.php",
} );
yadcf.init(table, [
{ column_number: 0,
filter_type: "range_number",
}
]);
} );
</script>
<title>Date filter bugs</title>
</head>
<body>
<table id="example">
<thead>
<tr>
<th>Date Created</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>
serverSide.php:
<?php
// DB table to use
$table = 'orders';
// Table's primary key
$primaryKey = 'id';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'status', 'dt' => 1 ),
array( 'db' => 'deadline', 'dt' => 2 ),
array( 'db' => 'master', 'dt' => 3 ),
array( 'db' => 'type', 'dt' => 4 ),
array( 'db' => 'brand', 'dt' => 5 ),
array( 'db' => 'device', 'dt' => 6 ),
array( 'db' => 'defect', 'dt' => 7 ),
array( 'db' => 'client', 'dt' => 8 ),
array( 'db' => 'cost', 'dt' => 9 ),
array( 'db' => 'icons', 'dt' => 10),
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'gsmcms',
'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' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
另外,我使用 ssp.class.php
我做错了什么?
【问题讨论】:
-
当使用
serverSide: true的数据表时,您必须在服务器端自行实现过滤逻辑,请参阅服务器端示例的 yadcf 展示源代码 github.com/vedmack/yadcf-showcase/blob/master/src/dr/yadcf/… -
好的,我明白了。但是我如何将此脚本连接到数据表。没有信息。请帮忙。你知道我该怎么做吗?
-
你可以在 github 上搜索,很多用户都有使用 yadcf 与 datatabkes 和 serverside 的 webapps 或在 datatables 论坛上提问
标签: jquery datatables yadcf