Error handling for serverside processing data table

Error handling for serverside processing data table

abhi05144abhi05144 Posts: 7Questions: 0Answers: 0
edited August 2012 in DataTables 1.9
Can anybody please tell me how to handle datatable error in case of any exception/error at backend (java ) processing.
I wanted to show a customized error to user. i tried
"error":handleAjaxError for datatable
and defined a function "handleAjaxError". but it seems it doesn't work for me.

Above one is working fine for me in case of ajax() call. but doesn't work for datatable()

Replies

  • abhi05144abhi05144 Posts: 7Questions: 0Answers: 0
    I am doing it in below way. There could be a beeter way of doing this. I would appreciate you on a beeter suggestion and reply.

    1. We can use 'fnServerData' for datatable(). We can add ajax() to fnServerData.and as we already know that we can handle success or error scenarion for ajax() request. As now datatable() is using ajax().

    2. So if something goes wrong at the backend ; it would be caught as error handling part of ajax().

    In this way we can put code of our interest for special care of errors and exceptions.


    Serverside datatable also works fine if we don't add 'fnServerData' and 'ajax()' with it but in that case we won't be able to show customized/generic error to user. datatable will keep showing "processing" option. At part of error handling we can navigate to a error page which could display a meaningful message to user.


    Below is the sample code for it. I would really appreciate if you could share another better approach of doing it.


    --->


    $("#locationData").dataTable(

    {

    "bServerSide": true,

    "bProcessing": true,

    "sAjaxSource": "/project/location_search.json",

    "fnServerData": function ( sSource, aoData, fnCallback ) {

    $.ajax( {

    "dataType": 'json',

    "type": "POST",

    "url": sSource,

    "data": aoData,

    "success": fnCallback,

    "error": handleAjaxErrorLoc // this sets up jQuery to give me errors

    } );

    },

    "sPaginationType": "full_numbers",

    "bJQueryUI": true,

    "sDom": '<"H"Tlfr>t<"F"ip>',

    "iDisplayLength": 15,

    //"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],

    "aLengthMenu": [[15,25, 50, 100, 200,500, 1000], [15,25, 50, 100, 200,500,1000]],

    "fnServerParams": function (aoData) {

    aoData.push(

    { "name": "searchLocation", "value":$("#locationValue").val()}

    );

    },



    "oTableTools": {

    "aButtons": [

    "copy", "xls", "pdf"



    ],

    "sSwfPath": "/telecoms/ext/jquery/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"

    }



    }


    );

    function handleAjaxErrorLoc( xhr, textStatus, error ) {

    // do handling of your interest

    }
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    fnServerData is the way to do this - you are absolutely correct :-). Then you have 100% control over the Ajax request / response.

    Allan
  • abhi05144abhi05144 Posts: 7Questions: 0Answers: 0
    :-)
    @Allan I am new to Ajax.... but your posts and datatables.net are much helpful to do all those analysis...
This discussion has been closed.