Server side send "auto" in filter
Server side send "auto" in filter
A77ak
Posts: 2Questions: 2Answers: 0
I'm having an odd issue related to server side processing using filter in some columns. Sometime, apparently in a random way, the server is receiving in filter1 (d.filter1) the value "auto", which is not an option in the select combo. Is there any way to avoid this?
Here is my code:
<div class="data-table">
<table id="js-table" class="table">
<thead>
<tr>
<th class="filter">Col1</th>
<th class="filter">Col2</th>
<th>Col3</th>
<th>Col4</th>
<th>Col5</th>
</tr>
</thead>
</table>
<div class="selects"></div>
</div>
var $tableCon = $('.data-table:eq('+ 1 +')');
var $table = $tableCon.find('.table');
var dataTable = $('#js-table').DataTable( {
"processing": true,
"serverSide": true,
"bFilter": false,
"ordering": false,
"bLengthChange": false,
"ajax": {
"url": "/agetdatatableaspx",
"type": "POST",
"data": function ( d ) {
var selects = document.getElementsByTagName('select');
if (selects.length > 0){
d.filter1= selects[0].value;
d.filter2 = selects[1].value;
}
}
},
initComplete: function(){
if (this.fnSettings().fnRecordsTotal() > 0){
$tableCon.find('.selects').insertBefore($('#js-table-hist'))
var counter = 0;
dataTable.columns('.filter').every( function (e) {
var column = this;
$tableCon.find('.selects').append('<div class="select-holder"><label><span class="label">'+ $table.find('thead th:eq('+ e +')').html() +'</span><select><option value="">- Todos -</option></select></label>');
var select = $tableCon.find('.selects .select-holder:eq('+ counter +') select')
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
column
.search( val ? '^'+val+'$' : '', true, false );
dataTable.draw();
});
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
counter++;
} );
}
});
This discussion has been closed.
Answers
Weird. DataTables shouldn't be setting a filter to
auto
ever, unless told to do so by an API call. It has no special meaning in DataTables the word "auto".Are you able to give me a link to the page showing the issue?
Allan