ajax.reload() with new data

ajax.reload() with new data

jaclerigojaclerigo Posts: 6Questions: 1Answers: 2
edited November 2014 in Free community support

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

  • jaclerigojaclerigo Posts: 6Questions: 1Answers: 2

    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 :(

  • jaclerigojaclerigo Posts: 6Questions: 1Answers: 2
    edited December 2014

    If anyone can help anyway...

  • WoldereWoldere Posts: 17Questions: 3Answers: 2
    edited December 2014

    You don't call your function buildSearchData? Or am I missing something here?

  • jaclerigojaclerigo Posts: 6Questions: 1Answers: 2

    I can do that, but the data from the selects is not updated on change anyway.

This discussion has been closed.