Why failed to take advantage of jQuery datatable processing on ajax server side?

I am using asp.net mvc5 and am trying to use djatery datatable server side data processing. Server-side processing tutorials show the format for returning the result from the server. But the difference in my project is that I cannot send a typed array for "data" from the server. I am sending all the text as a string with all the html tags. My data code is 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 ajax result is something like below

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

the data is similar to

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

because the view is common to many tables, and there are many situations that I have to control. This way I use StringBuilder on the server side. If I put success on ajax, the pagination elements will disappear at the bottom of the data. Why can't success be used in ajax? I have all the features of a datatable in common and is there a way to set features like iTotalRecords manually? I know that there is no forum with dates here. I regret it, but I spent a lot of time and cannot find a solution. I want to handle all the datatable functions in ajax success manually. I am using the latest datatable.

+5
source share
1 answer

I 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 delete fnCallback (msg), the next piece of data, including pagination, will disappear. I do not know exactly what he is doing, but this solved my problem.

+2
source

Source: https://habr.com/ru/post/1247685/


All Articles