Prevent data reload when change select value

Prevent data reload when change select value

ArgadesArgades Posts: 3Questions: 1Answers: 0

Hello,
I have a complex table which I load data based on a filter. When I assign values filter and pressed the button "search" data load me perfectly. The problem is when I go back to change one of the values of the filter as the item is automatically launches the search without having pressed the "Search" button.
Any idea how to prevent relaunch the data load?
Thanks in advance

Datatable v 1.10
JQuery v 2.2

`

    closeMessageError();
    clearTable(oTableNecesidadesDispos);
    var idxRender = 0;

    oTableNecesidadesDispos = $('#necesidadesDisposicionList').DataTable( {
        "destroy": true,
        "bProcessing": true,
        "bServerSide" : true,
        "bDeferRender": true,
        "iDisplayStart": 0,
        "iDisplayLength": 5,
        "stripeClasses": [ 'odd-row', 'even-row' ],
        "sAjaxSource" : "../../consulta/necesidades/loadNecesidadesDispos",
        "fnServerData": function ( sSource, aoData, fnCallback ) {

            var oModel = new Object()
            $(aoData).each(function (index, value)
            {
                if (value.name == "sEcho"){
                    oModel.sEcho = value.value
                } else if (value.name == "sColumns"){
                    oModel.sColumns = value.value;
                } else if (value.name == "iColumns"){
                    oModel.iColumns = value.value;
                } else if (value.name == "iDisplayStart"){
                    oModel.iDisplayStart = value.value;
                } else if (value.name == "sSearch"){
                    oModel.sSearch = value.value;
                } else if (value.name == "iSortingCols"){
                    oModel.iSortingCols = value.value;
                } else if (value.name == "iDisplayLength"){
                    oModel.iDisplayLength = value.value;
                }
            });

            $.ajax({
                "dataType": 'json', 
                "type": "POST", 
                "contentType": "application/json; charset=utf-8",
                "url": sSource, 
                "data": JSON.stringify({'fechaHora'   : $("#fechaHora").val(),
                                        'articulo'    : $("#codArticulo").val(),
                                        'canalProp'   : $("#canalProp").val(),
                                        'alarmas'     : $("#alarmas").val(),
                                        'alarmaTipo'  : $("#alarmasTipo").val(),
                                        'negativoRuta': $("#negativoRuta").val(),
                                        'pedidosPte'  : $("pedidosPte").is(":checked") ? true : false,
                                        dtParams: oModel}),  
                "success": fnCallback
            });
        },

        aaSorting: [[0]],
        //TRATAR LA RESPUESTA DE JSON
        "aoColumns": [
              { data: null,
                render: function (data, type, row, meta){
                    var html = renderItem(data, idxRender); //Render other table data

                    idxRender++;
                    return html;
                }
              }
         ],             

         "fnDrawCallback": function () {
             /*
              * CONVERTIR EN DATATABLE
              */
             var idx = 0;
             $('table').each(function(){
                 if (! $.fn.DataTable.isDataTable( this ) ) {
                    var oTable = $(this).DataTable({
                        retrieve:       true,
                        scrollY:        "100px",
                        scrollCollapse: true,
                        paging:         false,
                        aaSorting: [[0]] 
                    });

                    oTable.draw();
                 }
             });
         },         

        "oLanguage": {
            "sLengthMenu": "",
            "sInfo" : i18n["datatable.info.sInfo"],
            "sInfoEmpty" : i18n["datatable.info.sInfoEmpty"],
            "sInfoFiltered" : i18n["datatable.info.filtradas"],
            "sSearch" : "",
            "sLoadingRecords": i18n["datatable.info.loading.data"],
            "sZeroRecords" : i18n["datatable.info.norecords"]
         },

         "bInfo": true,
         "initComplete": function(settings, json) {
            if(json.iTotalRecords>0){
                $("#dlgPedidos").show();
            }else{
                $("#dlgPedidos").hide();
            }
         }

    });

`

Answers

  • ArgadesArgades Posts: 3Questions: 1Answers: 0
    edited September 2016

    Hello,
    I found the problem.
    The function that I use to clean the table is the one that causes the load is executed by the call back to the server

    clearTable function (oTable) { oTable.clear (); oTable.draw (); }

    Is there any other way to clean the table data?
    If I use ..clear().draw() then relaunch load data and don't remove de rows. I think that not remove because it render by method renderItem(...)
    Thanks

  • ArgadesArgades Posts: 3Questions: 1Answers: 0

    Hi,
    I have solved the problem and happens when the table.draw becomes () automatically executes the ajax call.

    $('#necesidadesDisposicionList').DataTable().destroy();

This discussion has been closed.