I try to build a custom filter for jquery Datatable. I have a form which has 3 select combos and on form submit I would like to pass to DatTable Object additional filter params and redraw my table but as it seems is not best approach what I'm tryin. My code
//here I build the table
oTable = $('#my_table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": url
.
.
.
"fnServerParams": function (aoData) {
if(brand !=''){
aoData.push({ "name": "brand", "value": brand});
} else if(shop !=''){
aoData.push({"name": "shop", "value": shop});
}
}
})
//here I try to pass variable to table Object
$('#filter_table').on('submit', function(e){
e.preventDefault();
brand = $("#filter_table :input[name='brand']").val();
shop = $("#filter_table :input[name='shop']").val();
prodcat = $("#filter_table :input[name='prod_cat']").val();
console.log(brand);
oTable.fnDraw();
});
But the variable value acts as HTML Object
I generate the markup dynamically with php as for example
<div class="form-group">
<label>Brand</label>
<select name ="brand" id ="brand" class="form-control">
<?php foreach ($filters['brands'] as $brand) : ?>
<option value="<?= $brand['brand'] ?>"><?= $brand['brand'] ?></option>
<?php endforeach; ?>
</select>
</div>