ajax.reload() with new data
ajax.reload() with new data
I'm trying to upgrade from older Datatables to the new Datatables 1.10. The problem is that I use form elements to create custom filters and would like to for example each time a select changes, the table reloads with the new data filtered.
here is part of the code:
var table = $('#main_table_<?=MODULO?>_<?=THIS?>').DataTable({
dom : 'T<"clearfix">lfrt<"clearfix">ip',
stateSave : true,
pageLength : 25,
pagingType : "full_numbers",
processing : true,
serverSide : true,
ajax : {
url : "<?=CAMINHO?>_lista_registos_busca.php",
data: buildSearchData
}
});
function buildSearchData(){
var obj = {
id_utilizador : $("select#id_utilizador option:selected").val(),
id_departamento : $("select#id_departamento option:selected").val(),
id_escritorio : $("select#id_escritorio option:selected").val(),
id_contrato_tipo : $("select#id_contrato_tipo option:selected").val(),
};
return obj;
}
$("select#id_utilizador, select#id_departamento, select#id_escritorio, select#id_contrato_tipo").change(function () {
table.ajax.reload();
});
ajax.reload() works great and data is properly sent, except that none of the Datatable parameters is sent. The alternative method:
var table = $('#main_table_<?=MODULO?>_<?=THIS?>').DataTable({
dom : 'T<"clearfix">lfrt<"clearfix">ip',
stateSave : true,
pageLength : 25,
pagingType : "full_numbers",
processing : true,
serverSide : true,
ajax : {
url : "<?=CAMINHO?>_lista_registos_busca.php",
data: {
id_utilizador : $("select#id_utilizador option:selected").val(),
id_departamento : $("select#id_departamento option:selected").val(),
id_escritorio : $("select#id_escritorio option:selected").val(),
id_contrato_tipo : $("select#id_contrato_tipo option:selected").val(),
}
}
});
Like this, all data is sent, ajax.reload() reloads the table but the data from the selects is not updated on change.
Any one of you guys can help me in solving this? Thanks in advance.
Answers
Rolling back to 1.9 ... can't find a sollution for this anywhere. Can't believe anyone ever used this for more complex data filtering. In 1.9 I can do it easy with fnServerData and aoData.push... in 1.10, can't figure it out :(
If anyone can help anyway...
You don't call your function buildSearchData? Or am I missing something here?
I can do that, but the data from the selects is not updated on change anyway.