Only 1 column is sorting properly
Only 1 column is sorting properly
elimariaaa
Posts: 30Questions: 11Answers: 0
Hello,
Here's the datatables debugger link.
I'm not sure why my 2 columns in a table are not sorting properly. When I click for the first column to sort, it works. But when I want it the other way around, it's not working. Only my date column is working.
Here's my code:
<script type="text/javascript">
var table;
$(document).ready(function() {
//datatables
var batches_table = $('#datatable-batches').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"responsive": true,
"order": [], //Initial no order.
"ajax": {
"url": "<?php echo site_url('oss/admin/ajax_batches'); ?>",
"type": "POST",
data: function ( data ) {
data.batch_no = $('#batch_no').val();
data.quantity = $('#quantity').val();
data.date_added = $('#date_added').val();
data.<?php echo $this->security->get_csrf_token_name(); ?> = '<?php echo $this->security->get_csrf_hash(); ?>';
},
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
]
});
$('#btn-filter_batches').click(function(){ //button filter event click
batches_table.ajax.reload(null,false); //just reload table
});
$('#btn-reset_batches').click(function(){ //button reset event click
$('#new-batch-form-filter')[0].reset();
batches_table.ajax.reload(null,false); //just reload table
});
$('.uk-form-small').addClass('form-control');
$('.alert-batch-box-data').css('visibility', 'hidden');
});
</script>
My table:
<table id="datatable-batches" class="table table-striped table-bordered forex-datatable">
<thead>
<tr>
<th>Batch #</th>
<th>Qty</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>Batch #</th>
<th>Qty</th>
<th>Date</th>
<th>Action</th>
</tr>
</tfoot>
</table>
The columns that are not sorting properly:
* Batch #
* Qty
Action column is disabled from sorting.
Any help is highly appreciated. Thanks!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You are using server-side processing (
serverSide
) so all sorting that is being done is being done by your server-side script. You'd need to debug that to make sure it is applying the search correctly.Allan
Hi Allan,
Yes, you're absolutely right. I debugged my server side code and is now working okay.
Thanks!