hi
to start sorry if my english is not very good I'm french.
I do not know how to explain that.
I put in my datatable row details ( https://datatables.net/examples/server_side/row_details.html ), but it does not work properly.
in the beginning everything works, on all the lines of my table.
when I change the category (ex: PUBG) it works, I can open row detail for my 3 lines, but when I put back without category (all games), only the first 3 lines work, I can not open row detail for others.
I dont understand why it does not work after.
someone can help me ?
my website : http://ckdn.esy.es/
table page html:
<table id="product_data" class="">
<thead>
<tr>
<th style="width: 28px;" ></th>
<th><i class="far fa-calendar-alt"></i></th>
<th><i class="far fa-user"></i></th>
<th><i class="far fa-gamepad"></i>
<select name="category" id="category" class="form-control">
<option value="">Touts les Jeux</option>
{$envoie} <!-- reçoit la boucle php -->
</select>
</th>
<th>Age</th>
</tr>
</thead>
</table>
script page html
<script type="text/javascript" language="javascript" >
$(document).ready(function (){
load_data();
function load_data(is_category)
{
var dataTable = $('#product_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"includes/fetch.php",
type:"POST",
data:{is_category:is_category}
},
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": 1},
{ "data": 2},
{ "data": 3,
"orderable":false,},
{ "data": 4 }
],
"language": {
"processing": "<div id='loader'></div>"
}
});
// affiche plus de détaille annonce
function format ( d ) {
if ( d[5] == '') {
$online = '<div class="steamWidget no-steam">'+
'Statut Steam: <p>Steam Non renseigné</p><br><br>'+
'Description Prochainement</div>';
} else {
if ( d[5] == 'online') {
$online = '<div class="steamWidget online">'+
'Statut Steam:<p>'+d[5]+'</p><br><br>'+
'Description Prochainement</div>';
}
else {
$online = '<div class="steamWidget offline">'+
'Statut Steam:<p>'+d[5]+'</p><br><br>'+
'Description Prochainement</div>';
}
}
return $online;
}
// affiche plus de détaille annonce suite
$(document).on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = dataTable.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format(row.data()) ).show();
tr.addClass('shown');
}
} );
}
// change la catégorie
$(document).on('change', '#category', function(){
var category = $(this).val();
$('#product_data').DataTable().destroy();
if(category != '')
{
load_data(category);
}
else
{
load_data();
}
});
</script>
And my fetch page:
require_once('../includes/config.php');
$connect = new mysqli($CONF['host'], $CONF['user'], $CONF['pass'], $CONF['name']);
if ($connect->connect_errno) {
echo "Failed to connect to MySQL: (" . $connect->connect_errno . ") " . $connect->connect_error;
};
$column = array("","date_add", "username", "category_g_name", "born");
$query = "
SELECT * FROM users U
INNER JOIN users_category UC ON (U.idu = UC.id_users)
INNER JOIN category_games C ON (UC.id_category = C.id)
";
$query .= " WHERE";
$query .= " UC.recherche = 1 AND";
if(isset($_POST["is_category"]))
{
$query .= " id = '".$_POST["is_category"]."' AND ";
}
if(isset($_POST["search"]["value"]))
{
$query .= '(date_add LIKE "%'.$_POST["search"]["value"].'%" ';
$query .= 'OR username LIKE "%'.$_POST["search"]["value"].'%" ';
$query .= 'OR category_g_name LIKE "%'.$_POST["search"]["value"].'%" ';
$query .= 'OR recherche LIKE "%'.$_POST["search"]["value"].'%" ';
$query .= 'OR born LIKE "%'.$_POST["search"]["value"].'%") ';
}
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY date_add DESC ';
}
$query1 = '';
if($_POST["length"] != 1)
{
$query1 .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$number_filter_row = mysqli_num_rows(mysqli_query($connect, $query));
$result = mysqli_query($connect, $query . $query1);
$data = array();
while($row = mysqli_fetch_array($result))
{
if (isset($row["steam"]))
{
$steam = simplexml_load_file("https://steamcommunity.com/profiles/".$row["steam"]."?xml=1", 'SimpleXMLElement', LIBXML_NOCDATA);
$steamstatut = str_replace("<br />", " - ", $steam->onlineState);
} else {
$steamstatut = '';
}
// calcule age user
$ub = explode('-', $row["born"]) ;
$age = date('Y') - $ub[0] ;
if ( date('md') < $ub[1].$ub[2] ) $age-- ;
//calcul nbr de our de l'annonce
$now = new DateTime("now");
$dateBdd = new DateTime($row["date_add"]);
//$date_add = $dateBdd1->diff($now)->format("%d jours, %h heurs and %i minutes");
$date_add = $dateBdd->diff($now);
$jours = $date_add->format("%d jrs");
$heurs = $date_add->format("%h hrs");
$minute = $date_add->format("%i min");
if ($jours == 0 ) {
if ($heurs == 0 ) {
$afficher = $minute;
}
else {
$afficher = $heurs;
}
} else {
$afficher = $jours;
}
$URL = $CONF['url'];
$sub_array = array();
$sub_array[] = '<th></th>';
$sub_array[] = $afficher;
$sub_array[] = $row["username"];
$sub_array[] = $row["category_g_name"];
$sub_array[] = $age. 'ans';
$sub_array[] = $steamstatut;
$data[] = $sub_array;
}
function get_all_data($connect)
{
$query = "SELECT * FROM users_category";
$result = mysqli_query($connect, $query);
return mysqli_num_rows($result);
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => get_all_data($connect),
"recordsFiltered" => $number_filter_row,
"data" => $data
);
echo json_encode($output);
thank a lot