iDisplayStart is set incorrectly when pressing "Next"

iDisplayStart is set incorrectly when pressing "Next"

octavoctav Posts: 18Questions: 0Answers: 0
edited September 2013 in General
Hi.
I use datatables with server side processing and when pressing Next I get a very strange behavior. If "1" is selected in pagination links, it works ok; however, if page "2" is currently selected, pressing next will set iDisplayStart to the value "1010" which corresponds to page 102.

This is my initialization code:

oTable = $('#solutionsTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bSort": false,
"oLanguage": {
"sSearch": "Search all columns:"
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '@Url.Action("AsyncGetUserData")',
"bDeferRender": true,
"aoColumns": [
//User
{ "mData": function(source, type, val){
var returnString = "Name: " +"" + source.userName + "" +
"
Type: " + "" + source.roleName + "
" +
"Status: " + "" + source.isActive + "";
return returnString;
}},
//Activity
{ "mData": function(source, type, val){
var returnString = "Logins Number: " + source.loginsNum +
"
Last Login: " + source.lastLogin;
return returnString;
}},
//Contact
{ "mData": function(source, type, val){
var returnString = "First Name: " + source.firstName +
"
Last Name: " + source.lastName +
"
Email: " + source.email +
"
Phone: " + source.phone;
return returnString;
}},
//Work
{ "mData": function(source, type, val){
var returnString = "Company: " + source.company +
"
Job title: " + source.job;
return returnString;
}},
//Address
{ "mData": function(source, type, val){
var returnString = "Country: " + source.countryName +
"
City: " + source.city +
"
Street: " + source.street +
"
Postcode: " + source.postcode;
return returnString;
}},
//Options
{ "mData": function(source, type, val){
var editUrl = '@Url.Action("Account", "CMS")' + '?userId=' + source.userID;

var returnString = "Edit" + " / " +
"Delete";
return returnString;
}}
]
}).fnSetFilteringDelay();

and this is the JSON object I return:

return Json(new
{
sEcho = int.Parse(param.sEcho),
iTotalRecords = allUsers.Count(),
iTotalDisplayRecords = filteredResults.Count(),
aaData = result
}, JsonRequestBehavior.AllowGet);

I cannot post a link to the issue, unfortunately.

Replies

  • octavoctav Posts: 18Questions: 0Answers: 0
    PS: if any other table page is selected except 1 and 2, "Next" link will not work whatsoever, without any javascript error and without posting to the controller
  • octavoctav Posts: 18Questions: 0Answers: 0
    Pressing Next the first time makes the info string write: "Showing 1 to 10 of 1056 entries";
    pressing Next the second time makes the info string write : "Showing 0101 to 1,010 of 1,056 entries"; pressing next the third time makes the pagination mechanism jump to page 102, iDisplayStart is set to 1010, the query string is

    http://localhost/Archimede.Web/INT/CMS/AsyncGetUserData?sEcho=4&iColumns=6&sColumns=&iDisplayStart=01010&iDisplayLength=10&mDataProp_0=function.

    I read a post saying this means server-side process may be returning strings instead of integers. I don't think this is the case, though. This is is what I return in the JSON object:

    return Json(new
    {
    sEcho = param.sEcho,
    iTotalRecords = allUsers.Count(),
    iTotalDisplayRecords = filteredResults.Count(),
    aaData = result
    }, JsonRequestBehavior.AllowGet);
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sounds like you are passing back `iTotalRecords` and `iTotalDisplayRecords` as strings - not integers, as is required.

    Allan
  • octavoctav Posts: 18Questions: 0Answers: 0
    I found the answer: I was using an implementation of fnLengthChange to set programatically iDisplayStart and iDisplayLength; it was part of a mechanism to save number of entries showed in a cookie and the set the value when needed; I removed that and impelemented state savinf using local storage and the problem dissapeared. Thanks for the support.
This discussion has been closed.