Reputation: 1
YADCF tied to datatables, the data is loaded, but work only text and conventional filters. Range_number not work, with any number - No matching records found. If i disable the option server side, everything starts to work like a miracle. Please, help me. Index.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 )
);
?>
Also, I use ssp.class.php
What am I doing wrong?
Upvotes: 0
Views: 731
Reputation: 389
There is a php library on https://datatables.ozdemir.be/custom-filter2
here is the way how it can be applied to yadcf. The library has the ability to create custom filters as you need.
<?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();
Upvotes: 0