Datatables extra rows disturps sorting and searching option
Datatables extra rows disturps sorting and searching option
Muiter
Posts: 4Questions: 3Answers: 0
I am using this code to create a datatable and that works fine.
<table width="100%" class="table table-striped table-hover" id="dataTables-table_1" data-page-length='25' data-order='[[ 1, "desc" ]]'>
<thead>
<tr>
<th>Dossier</th>
<th>Orderno.</th>
<th>Klant</th>
<th>Ref</th>
<th>Contact</th>
<th>Leverdatum</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
// query table_1
$sql_table_1 = *** query ***
if(!$res_table_1 = mysqli_query($mysqli, $sql_table_1)) { echo '<div class="alert alert-danger text-center" role="alert">Er is helaas iets fout gegaan.</div>'; die; }
while($row_table_1 = mysqli_fetch_array($res_table_1)){ $i++;
echo'
<tr>
<td>'.$row_table_1['dossier_nr'].'</td>
<td>'.$row_table_1['order_nr'].'</td>
<td>'.$row_table_1['relatie_naam'].'</td>
<td>'.$row_table_1['klant_ref'].'</td>
<td>'.$row_table_1['contact_naam'].'</td>
<td '.$style.'>'.$row_table_1['datum_leveren_dmy'].'</td>
<td><span class="label label-warning">In productie</span></td>
</tr>';
}
?>
</tbody>
</table>
But I would like to enter some more information a new <tr>
line. But when I do this I lose the sorting and searching option in the header.
echo'
<tr>
<td>'.$row_table_1['dossier_nr'].'</td>
<td>'.$row_table_1['order_nr'].'</td>
<td>'.$row_table_1['relatie_naam'].'</td>
<td>'.$row_table_1['klant_ref'].'</td>
<td>'.$row_table_1['contact_naam'].'</td>
<td '.$style.'>'.$row_table_1['datum_leveren_dmy'].'</td>
<td><span class="label label-warning">In productie</span></td>
</tr>
<tr>
<td colspan="7">Some extra information</td>
</tr>';
If I use an extra <tbody>
tag the sorting and searching options are restored but the color of the rows are the same instead of striped.
echo'
<tr>
<td>'.$row_table_1['dossier_nr'].'</td>
<td>'.$row_table_1['order_nr'].'</td>
<td>'.$row_table_1['relatie_naam'].'</td>
<td>'.$row_table_1['klant_ref'].'</td>
<td>'.$row_table_1['contact_naam'].'</td>
<td '.$style.'>'.$row_table_1['datum_leveren_dmy'].'</td>
<td><span class="label label-warning">In productie</span></td>
</tr>
<tbody><tr>
<td colspan="7">Some extra information</td>
</tr></tbody>';
Any suggestions how to get this all right?
This discussion has been closed.
Answers
Hi @Muiter ,
Yep, DataTables expects the table to be a uniform size (all columns on all rows) when the table is initialised - otherwise it will mess up the column sorting and filtering. This SO thread does discuss a hack of adding invisible columns as a workaround which would give you your desired effect.
Cheers,
Colin