Load Data - newbie

Load Data - newbie

stefanistefani Posts: 6Questions: 0Answers: 0
edited May 2012 in General
Hi,

I'm testing DataTable on mvc application (Razor Engine).
I've put this on my cshtml


$(document).ready(function () {
$('#ClientList').dataTable({
"bProcessing": true,
"bDeferRender": true,
"sAjaxSource": 'JRicercaClienti'
});
});


into the controller

public ActionResult JRicercaClienti()
{
var Clienti = new List();
var query = DB.tb_clifor.Where(m => m.k_clifor >= 0 && m.cognome != "" && m.nome != "").ToList();


return Json(new { aaData = query.Select(m => new string[] { m.cognome, m.nome, m.indirizzo}) }, JsonRequestBehavior.AllowGet);
}

Question: can DataTable load only 10/25 records at time and load them when user click button next/prev?
In this case, My application load all data at once...I don'tlike that.

Regards.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > Question: can DataTable load only 10/25 records at time and load them when user click button

    Yes - use server-side processing :-).

    Docs: http://datatables.net/usage/server-side
    Example: http://datatables.net/release-datatables/examples/data_sources/server_side.html

    Allan
  • stefanistefani Posts: 6Questions: 0Answers: 0
    Hi,

    I'm try it.
    Now I've changed controller and cshtml.
    But why when I click next, $(document).ready(function () don't reload?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > But why when I click next, $(document).ready(function () don't reload?

    What next? The paging control? It doesn't reload the Javascript function - no. Have a look in Firebug and you'll see it make an Ajax request for more data.

    Allan
  • stefanistefani Posts: 6Questions: 0Answers: 0
    Solved it.
    Regards
This discussion has been closed.