Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not allowed using success in jquery datatable server side processing ajax?

I am using asp.net mvc5 and trying to use jquery datatable plugin server-side processing. The tutorials of server side processing show a format for returning result from server.But the difference in my project is that i cannot send a typed array for 'data' from server. I am sending whole tbody as string with all html tags. My datatable code as below.

  var e = t.DataTable({processing: true, 
        serverSide: true,
        info: true,   
        stateSave: true, 
        PaginationType: "full_numbers",
        ajax:{
            "url": '@Url.Action("AjaxGetJsonData","Define",new { tablename= @HttpContext.Current.Request.QueryString["tablename"] })',
            "type": "GET",
            "success": function (result) {
                console.log(result);

                $("#sample_1").find("tbody").html(result.data);
                $("#sample_1_processing").hide();
                Init();
                //var oSettings = $("#sample_1").dataTable().fnSettings();
                //oSettings.iTotalRecords = result.recordsTotal;

            }

        }

The Result of ajax is something like as below,

Object {draw: 1, iTotalRecords: 25000, iTotalDisplayRecords: 0, data: Array[1]}

the data is like

<tr><td></td><td></td><td></td><td></td></tr>

because the view is generic for many tables and there are many situation that i should control.Thus, i am using StringBuilder in server side. If i put success to ajax the pagination elements disappear at the bottom of datatable. Why it is not allowed to use success in ajax? i have all total features of datatable and is there any way to set features like iTotalRecords manually ? I know here is not datatable forum. I am sorry about this but i spent time a lot and cannot find solution. I want to handle all features of datatable in ajax success manually.I am using last version of datatable.

like image 376
emres Avatar asked Oct 18 '22 11:10

emres


1 Answers

I have solved my problem at the end.There is something interesting but i can use success now.

var e = t.DataTable({
        processing: true,
        serverSide: true,
        info: true,
        stateSave: true,
        PaginationType: "full_numbers",
        "sAjaxSource": '@Url.Action("AjaxGetJsonData","Define")',
        "fnServerData": function (sSource, aoData, fnCallback) {
            aoData.push({ "name": "tablename", "value": $("#temprory").val() });
            console.log(aoData);
            $.ajax({
                url: sSource,
                type: "POST",
                data: aoData,
                success: function (msg) {
                    fnCallback(msg);
                    console.log(msg);
                    $("#sample_1").find("tbody").html(msg.data);
                    $("#sample_1_processing").hide();
                    Init();
                }
            });
        }

The interesting point is that if you remove fnCallback(msg), the below part of datatable that includes pagination disappears. I dont know exactly what it does but this solved my problem.

like image 175
emres Avatar answered Oct 28 '22 21:10

emres