Datatables server side processing how to intercept json response and call an action

Datatables server side processing how to intercept json response and call an action

Anedu1Anedu1 Posts: 3Questions: 1Answers: 0

Hello,

I need help with a data table that needs server side processing. I am using an MVC app . The example that I am testing on works find it sends the data from the data table to an action and the action does the filtering and sorting and sends a JSON response that is then use to render the table again.

What I need is to have the json response not be used as the rendering source but instead call another action and send the json as parameter and have the action do the work.

$(document).ready(function () {
$('#myGrid').DataTable(
{
"processing": true,
"serverSide": true,
"ajax": {
"url": "../DataT/sproc/",

                },
                "columns": [
                { "data": "SalesOrderID" },
                { "data": "SalesOrderDetailID" },
                { "data": "CarrierTrackingNumber" },
                { "data": "OrderQty" },
                { "data": "ProductID" },
                { "data": "UnitPrice" }]
            }



            );
    })

So I need some sort of way to have a call back function that runs on success how can I do that?

Answers

  • Anedu1Anedu1 Posts: 3Questions: 1Answers: 0

    It looks that I will need a complete option as show below:

    "ajax": {
    url: "calendar_ajax.aspx?method=showrecurringevents_load&method=showrecurringevents&id=0&id2=0&newvalue=&cal_id=3188&t=1455268695315&coreid="
    , dataType: "json"
    , complete: function() {
    paintcheckboxes("recurringtable")
    }
    , error: function (xhr, error, thrown) {
    alert("An error occurred while attempting to retrieve data via ajax.\n"+thrown );
    }
    , }

    But on top of that I need a way to prevent ajax to load the return values and instead let the action take over the rendering part

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    here is a stub, based on some stuff I did a while ago, that my get you headed in the right direction.

                var table = $('#example').DataTable({
                    "processing": true,
                    "serverSide": true,
                    "rowCallback": function (row, data) {
                    },
                    preDrawCallback: function (settings) {
    
                    },
    
                    rowId:"employeeId",
                    "createdRow": function (row, data, dataIndex) {},
                    "columns":  [
                        { "data": "name" },
                        { "data": "position" },
                        { "data": "office" },
                        { "data": "extn" },
                        { "data": "start_date" },
                        { "data": "salary" }
                    ],
                    "select":"multi",
                    "lengthMenu": [5, [10, 15, 25, 50, -1], [5, 10, 15, 25, 50, "All"]],
                    "pageLength": 5,
                    "ajax": function (request, drawCallback, settings) {
                        runAjax(settings).done(function (response) {
                        
                            drawCallback(response);
                        });
                    },
                    order: [[0, 'asc']]
                });
    
        function runAjax(settings) {
                var deferred = new $.Deferred();
                $.ajax({
                    contentType: "application/json; charset=utf-8",
                    url: "wsSample.asmx/GetDTDataUnserializedObject",
                    type: "Post",
                    data: JSON.stringify({ dtParameters: { draw: 0, start: start, length: pageInfo.length * 5 } }),
                    success: function (response) {
    
                            deferred.resolve({ data: response.d.data });
                     },
                    error: function (error) {
           
                        deferred.fail(error);
                    }
                });
                return deferred.promise();
            }
    
    
  • Anedu1Anedu1 Posts: 3Questions: 1Answers: 0

    Thank you for your response.

    I will have to parse through your answer carefully to catch up .

This discussion has been closed.