【问题标题】:YADCF server side and range_number (not working)YADCF 服务器端和 range_number(不工作)
【发布时间】: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


【解决方案1】:

https://datatables.ozdemir.be/custom-filter2上有一个php库

这是如何将其应用于 yadcf 的方式。该库能够根据需要创建自定义过滤器。

<?php
require_once 'vendor/autoload.php';

use Ozdemir\Datatables\Datatables;
use Ozdemir\Datatables\DB\SQLite;

$path = dirname(__DIR__).'/database/Chinook_Sqlite_AutoIncrementPKs.sqlite';
$dt = new Datatables(new SQLite($path));

$dt->query('Select TrackId, Name from Track ');

$dt->filter('TrackId', function () {
    if ($this->searchValue() === '-yadcf_delim-') {
        return '';
    }
    $val = explode('-yadcf_delim-', $this->searchValue());
    return $this->between($val[0], $val[1] ?? null);
});

echo $dt->generate();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 2012-05-05
    • 2015-08-26
    • 1970-01-01
    相关资源
    最近更新 更多