Datatable dont draw my column when i choose my select filter
Datatable dont draw my column when i choose my select filter
rhmtlubis
Posts: 1Questions: 1Answers: 0
Here I am filtering Datatable on the value selected from dropdown list.my script code is as below.
Here's the relevant parts of the dataTable configuration:
i can not get them working at all and can't figure out why or what i'm doing wrong. Im stuck with this, anybody can help me?!
$(document).ready(function () {
//datatables
table = $('#productstable').DataTable({
"initComplete": function () {
this.api().columns().every( function (i) {
if (i == 2) {
var selectId = "#selectbyname";
var column = this;
var select = $(selectId)
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
});
}
});
},
"searching": true,
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
responsive: true,
<?php datatable_lang();?>
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo site_url('products/product_list')?>",
"type": "POST",
'data': {'<?=$this->security->get_csrf_token_name()?>': crsf_hash,'group': '<?=$this->input->get('group')?>'}
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [0], //first column / numbering column
"orderable": false, //set not orderable
},
{
"targets": [2],
"visible": false
}
],
dom: 'Blfrtip',lengthMenu: [10, 20, 50, 100, 200, 500],
buttons: [
{
extend: 'excelHtml5',
footer: true,
exportOptions: {
columns: [1, 2, 3, 4, 5, 6]
}
}
],
});
});
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin