server side processing and manipulating data returned

server side processing and manipulating data returned

shavo30shavo30 Posts: 2Questions: 1Answers: 0

I am using datatables version 1.10.0 for search capability.

I want to know for server side processing how do i manipulate the response. For example I have a json response that returns with the records to display and also a status.

My requirement is, if there is validation failure on the server side, I do not want to draw the table and instead, render error messages on screen. Otherwise if success draw the table.

Simple Example below:

$('#result').dataTable( {
        "processing": true,
        "serverSide": true,

        "ajax": {
            "url": "search",
            "type": "POST",
            //"dataSrc": "resultList",
            "dataSrc": function ( json ) {
        if (json.responseStatus.value == 'Validation Failure') {
    //show error messages on screen
//prevent redraw
         } else {

    //draw the table with the  resultList
    }
              }
        "columns": [
                    { "data": "referenceNumber"},
                    { "data": "fileName" },
                    { "data": "documentType" },
                    { "data": "uploadType" },
                    { "data": "createdBy" },
                    { "data": "memberName" },
                    { "data": "dateOfBirthStr"},
                    { "data": "createdDateStr" },
                    { "data": "comment" },
                    { "data": "status" }
                ]
    } ); 

Is this possible?

Thanks.

Answers

  • shavo30shavo30 Posts: 2Questions: 1Answers: 0
    edited October 2014

    UPDATE:
    On the server side I return 403:

    return new ResponseEntity<SearchUploadResponse>(searchUploadResponse, HttpStatus.FORBIDDEN);

    On the client side:

        $('#result').dataTable( {
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "search",
                "type": "POST",
                "dataSrc": "resultList",
                         error: function (jqXHR, textStatus, errorThrown) {
                               //handle errorThrown in here
                             alert("error" + jqXHR  + " : " + textStatus + " : " + errorThrown);
                         }
            } ,
    

    The result is i can show my error messages.
    datatables blocks access to the table with the "processing" div.

    Is this the correct approach?

This discussion has been closed.