Loading ajax source twice in v1.10?
Loading ajax source twice in v1.10?
A95
Posts: 9Questions: 0Answers: 0
Hi, I saw a discussion before about this issue, they say that in the version 1.8 the issue was resolved. I am having the same issue now and I am working in the 1.10 version, I don't know why but is calling the load function in the server code twice. If someone have the same issue or recommend me something, I will appreciate it.
This discussion has been closed.
Replies
I use this code inside of a function to initialize the datatable:
I don't immediately see why that would happen from the above code. Can you link to a page showing the issue so I can debug it please.
Allan
Sorry, I can't show you the page, because company restrictions, but I am using it in a MVC application. So I have a view which have the table defined, in that view I included the js file that had the function to handle the datatable, all is working fine, except the twice call that the ajax do to the controller class to load the data. In the controller class I have a function that handle the data a return a json to the view with the data. I will give a breve description that I have to you can get more close to that I have actually:
View:
using ModelClass
<link href="@Url.Content("~/Content/bootstrap.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/bootstrap-datetimepicker.min.css")" rel="stylesheet" />
text
<script type="text/javascript" src="@Url.Content("~/Scripts/STS/Maintenance/CRML.js")"></scrip>
JS File:
var RRowData = null;
$(document).ready(function () {
ttable = 0;
});
...
//Create the datatable
function s_getDataTable() {
var table = $('#convResTabR').DataTable({
"serverSide": true,
"orderMulti": false,
"bProcessing": true,
"order": [[3, "desc"], [1, "asc"]],
"ajax": {
"url": "/Maintenance/LoadData",
"type": "POST",
"data": function (d) {
d.LoT = ttable;
d.SO = r;
},
"datatype": "json"
},
"aoColumnDefs": [
{
"data": "DctN",
"name": "D N",
"visible": true,
"aTargets": [0],
"bSortable": true
},
{
"data": "Conme",
"name": "C N",
"visible": true,
"aTargets": [1],
"bSortable": true
},
{
"data": "TeN",
"name": "T N",
"visible": true,
"aTargets": [2],
"bSortable": true
},
{
"data": "BgVdDate",
"name": "B V D",
"visible": true,
"aTargets": [3],
"bSortable": true,
"mRender": function (data, type, full) {
var result = "";
if (data != null) {
if (data.indexOf("Date") > -1) {
var valueDate = new Date(parseInt(data.replace(/\/+Date(([\d+-]+))\/+/, '$1')));
var curr_date = valueDate.getDate().toString();
var curr_month = valueDate.getMonth() + 1; //Months are zero based
var curr_year = valueDate.getFullYear().toString();
result = curr_month + "/" + curr_date.toString() + "/" + curr_year;
}
else
result = data;
}
return result;
}
},
{
"data": "EVaD",
"name": "E V D",
"visible": true,
"aTargets": [4],
"bSortable": true,
"mRender": function (data, type, full) {
var result = "";
if (data != null) {
if (data.indexOf("Date") > -1) {
var valueDate = new Date(parseInt(data.replace(/\/+Date(([\d+-]+))\/+/, '$1')));
var curr_date = valueDate.getDate().toString();
var curr_month = valueDate.getMonth() + 1; //Months are zero based
var curr_year = valueDate.getFullYear().toString();
result = curr_month + "/" + curr_date.toString() + "/" + curr_year;
}
else
result = data;
}
return result;
}
},
{
"data": "R",
"name": "R",
"visible": true,
"aTargets": [5],
"bSortable": true
},
{
"data": "LA",
"name": "Exc",
"visible": true,
"aTargets": [6],
"bSortable": true
},
{
"data": "SR",
"name": "S R",
"visible": true,
"aTargets": [7],
"bSortable": true
},
{
"data": "CN",
"name": "C N",
"visible": true,
"aTargets": [8],
"bSortable": true
},
{
"data": "CR",
"name": "C R",
"visible": true,
"aTargets": [9],
"bSortable": true
},
{
"data": "CSR",
"name": "C S R",
"visible": true,
"aTargets": [10],
"bSortable": true
},
{
"data": "LaUpdB",
"name": "L U B",
"visible": true,
"aTargets": [11],
"bSortable": true
},
{
"data": "LaUpOn",
"name": "L U O",
"visible": true,
"aTargets": [12],
"bSortable": true,
"mRender": function (data, type, full) {
var result = "";
if (data != null) {
if (data.indexOf("Date") > -1) {
var valueDate = new Date(parseInt(data.replace(/\/+Date(([\d+-]+))\/+/, '$1')));
var curr_date = valueDate.getDate().toString();
var curr_month = valueDate.getMonth() + 1; //Months are zero based
var curr_year = valueDate.getFullYear().toString();
result = curr_month + "/" + curr_date.toString() + "/" + curr_year;
}
else
result = data;
}
return result;
}
},
{
"aTargets": [13],
"data": "RId",
"className": "center",
"bSortable": false,
"mRender": function (data, type, full) {
var btn = Core.stringFormat('<button style="width:80px;font-size:10px;" type="button" data-role="edit" data-id="{0}" >Edit</button>', data);
btn += Core.stringFormat('<button style="margin-top:5px;width:80px;font-size:10px;" type="button" data-role="delete" data-target="#confirm-delete" data-id="{0}">Delete</button>', data);
return Core.stringFormat('
', btn);
}
}],
"fnDrawCallback": function () {
var holder = $("#convResTabR").find("tbody");
var btns;
var btens;
//Edit button
btens = holder.find("button[data-role='edit']");
btens.button({
icons: {
primary: " ui-icon-pencil"
}
});
btens.off("click");
btens.on("click", function () {
var id = $(this).data("id");
var row = $(this).closest("tr").get(0);
// Get the data array for this row
//var rowData = table.row(row).data();
var rowData = MC.ATable.row(row).data();
}
Controller:
[HttpPost]
public ActionResult LoadData()
{
return LoadDataTableData(Request);
}
That is the more close that I can get you, but the weird is why it is doing the twice calling from ajax.
Also the version of the datatable that I have is version 1.10.12
I don't immediately see anything from the above code and none of my examples appear to demonstrate this issue. Without being able to debug it myself, the best I can suggest is that you put a breakpoint into the code where the Ajax request is made (your
ajax.data
function might be the easiest place to do that) and look at the back trace to see what is causing the second draw to occur.Allan
Hi Allan, all fixed, was a section in my code that call it twice, sorry for the comment, is working perfect right now.
No worries - thanks for the update. Good to hear you have it working now!
Allan