how to prevent data table reloading automatically during any datatable event.

how to prevent data table reloading automatically during any datatable event.

murali sankarmurali sankar Posts: 1Questions: 1Answers: 0

Hi,

i have a data table that loads data from json (responsce from spring controller using ajax). but after performing any event on datatable (i.e search box, deleting a row....) the ajax call getting executed and data getting restored for every event on datatable.
i would like to load the data only two times 1 during initial page load 2 when i call table.ajax.reload().
here is my code:

  $('#tbl').DataTable({
                   "bServerSide": true ,
                   processing: true,
                  "scrollY":        "200px",
                    "scrollCollapse": true ,
                    dom: 'Bfrtip',
                    "bPaginate": false,
                    "bInfo" : false,
                    
                     "ajax": {
                        "url": $("#Form").attr("action")+'/getAlltabledataList',
                        "type": "GET",
                        "dataSrc": "",
                        "data": function(response){
                         
                          return JSON.stringify(response);
                        },
                        "contentType": "application/json;charset=UTF-8"
                      },
                      'aoColumns' : [{'mData' : 'code'},
                                       { 'mData': 'description' }],
                      
                                   
                    buttons: [
                         { extend: 'excel', text: 'Export' }
                    ]
              });  
             
            
              var table = $('#tbl').DataTable();

// delete selected row from datatable 
                   $('#ConfrmDeleteBtn').click( function () {
                var data = 'code='
                   + encodeURIComponent(selectedLVCode);
                
               $.ajax({
                 url : $("#Form").attr("action")+'/deleteLV',
                 data : data,
                 type : "POST",
                 success : function(response) {
                        
                        if(response=='success'){
                        
                             table.row('.selected').remove().draw( false );
                        }else{
                            alert('problem occured while deleting :'+response);
                        }
                    },
                  error : function(xhr, status, error) {
                          alert(xhr.responseText);
                    }
               });
             
              $("#dialog").dialog('close');
           } );

here after deleting selected row,again datatable ajax call is getting executed without i calling table.ajax.reload();
and also i see the table ajax call happening for every search on datatable.
could someone please help me in this.

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,393Questions: 26Answers: 4,786
    edited February 2018 Answer ✓

    Since you are using server side processing every draw, search, order, etc of the table is going to request data from the server. With server side processing the only data at the client is the page being displayed.

    If you don't enable server side processing then all those functions are performed on the client. However that means all of the data is loaded with the ajax request and table.ajax.reload().

    Kevin

This discussion has been closed.