How to handle the Errors Display if I use columns directly.

How to handle the Errors Display if I use columns directly.

OmniwyseOmniwyse Posts: 29Questions: 11Answers: 0
edited November 2022 in Free community support

Normally after ajax call we will use Success and Errors as mention below without columns.

success: function(data) {           
        if("success" === data.status){
                        d = transform(data);
            searchResults.clear();
                        searchResults.rows.add(data).draw();
            
        }
        if("error" === data.status){
            deleteCreditCards();
        }
        },
       error : function(data){
         
       } 

But now I am using columns With columns suppose from backend I got error how to display them using coumns.I should have the columns and I need to check the status which we got from backend.

 "ajax": {
    "url": extract_url('/refund/list'),
    "data": function ( d ) {
        var sortingColumn=d.order[0].column;
        var sortingOrder=d.order[0].dir;
        
        d.orderColumn=sortingColumn,
        d.order=sortingOrder;
        d.search = search,
        d.fromDate = fromDate,
        d.toDate = toDate,
        delete d.columns;
    }
  },
    columns: [
      
         {title: "Activity Id", data: "id",
           "render":function(data,type,row,meta){
             data = data !=null ? data:notAvailable;
             return data;            
         }},
         {title: "Date", data: "dateTime",
           "render":function(data,type,row,meta){
             data = moment(data).tz(tenantTimeZone).format(displayFormat);
             return data;            
         }}]

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    If I understand the question correctly you are moving from using the jQuery ajax() to the ajax option. In the ajax docs there is this statement:

    success - Must not be overridden as it is used internally in DataTables. To manipulate / transform the data returned by the server use ajax.dataSrc (above), or use ajax as a function (below).

    Instead of success use the ajax.dataSrc or the xhr event to process this error check:

            if("error" === data.status){
                deleteCreditCards();
            }
    

    There is also this statement:

    As an object, the ajax object is passed to jQuery.ajax allowing fine control of the Ajax request. DataTables has a number of default parameters which you can override using this option. Please refer to the jQuery documentation for a full description of the options available

    This indicates that you can still use the error option as it will be passed to jQuery ajax().

    Kevin

Sign In or Register to comment.