Why Scroller Call once but get the Whole DataTable?
Why Scroller Call once but get the Whole DataTable?
chelseajcole
Posts: 12Questions: 0Answers: 0
I am using DataTable Scroller plug-in to get the DataTable page by page. But once I run the code, I get the whole datatable, it still cost a long time. But when I drag the scrollbar to the end, it make another Ajax call to the get the same dataTable again. Please help.
I am using ASP.NET MVC, here is my view:
[code]@{
Layout = null;
}
<!DOCTYPE html>
JQuery DataTables/ASP.NET MVC Integration
td { white-space: nowrap; }
$(document).ready(function () {
var oTable =
$('#myDataTable').dataTable({
"sScrollY": "400px",
"sAjaxSource": "Home/AjaxHandler",
"bProcessing": true,
"bServerSide": true,
"sDom": "frtiS",
"bDeferRender": true,
"bStateSave": true
});
});
Index
ID
Company name
Address
Town
[/code]
Here is my controller:
[code] using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JQueryDataTables.Models;
using JQueryDataTables.Models.Repository;
namespace JQueryDataTables.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult AjaxHandler()
{
var allCompanies = DataRepository.GetCompanies();
var result = from c in allCompanies select new[] { Convert.ToString(c.ID), c.Name, c.Address, c.Town };
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = allCompanies.Count(),
iTotalDisplayRecords = allCompanies.Count(),
aaData = result
},
JsonRequestBehavior.AllowGet);
}
} [/code]
I am using ASP.NET MVC, here is my view:
[code]@{
Layout = null;
}
<!DOCTYPE html>
JQuery DataTables/ASP.NET MVC Integration
td { white-space: nowrap; }
$(document).ready(function () {
var oTable =
$('#myDataTable').dataTable({
"sScrollY": "400px",
"sAjaxSource": "Home/AjaxHandler",
"bProcessing": true,
"bServerSide": true,
"sDom": "frtiS",
"bDeferRender": true,
"bStateSave": true
});
});
Index
ID
Company name
Address
Town
[/code]
Here is my controller:
[code] using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JQueryDataTables.Models;
using JQueryDataTables.Models.Repository;
namespace JQueryDataTables.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult AjaxHandler()
{
var allCompanies = DataRepository.GetCompanies();
var result = from c in allCompanies select new[] { Convert.ToString(c.ID), c.Name, c.Address, c.Town };
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = allCompanies.Count(),
iTotalDisplayRecords = allCompanies.Count(),
aaData = result
},
JsonRequestBehavior.AllowGet);
}
} [/code]
This discussion has been closed.